Ejabberd OAuth/REST 401 未经授权 [英] Ejabberd OAuth / REST 401 Unauthorized

查看:32
本文介绍了Ejabberd OAuth/REST 401 未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 /api/connected_users 端点请求 Ejabberd REST Web 服务,但该请求总是返回 401 未经授权的 HTTP 错误.

I'm trying to request the Ejabberd REST Web Services with the /api/connected_users endpoint but the request always returns me 401 Unauthorized HTTP errors.

这是我的 OAuth 配置.

Here is my OAuth configuration.

 - 
port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws
  # OAuth Support
  "/oauth": ejabberd_oauth
  # ReST API:
  "/api": mod_http_api
web_admin: true
http_bind: true
register: true
captcha: false

...    

commands_admin_access: configure
commands:
  - add_commands: user
oauth_expire: 3600
oauth_access: all

如文档中所述,我使用以下 URL 为 admin 用户生成 OAuth 2 访问令牌.

As explained in the documentation I use the following URL to generate an OAuth 2 Access Token for the admin user.

http://localhost:5280/oauth/authorization_token?response_type=token&client_id=myclient&redirect_uri=http://localhost:5280&scope=sasl_auth

它返回我的 OAuth 令牌.

It returns me my OAuth Token.

http://localhost:5280/?access_token=oLn8Hebh051l2PdCM15tSvHrEI25CpBs&token_type=bearer&expires_in=3600&scope=sasl_auth&state=

最后要请求 api/connected_users 端点,我执行以下操作.

Finally to request the api/connected_users endpoint I do the following.

curl -v -X GET -H "X-Admin: true" -H "Authorization: Bearer oLn8Hebh051l2PdCM15tSvHrEI25CpBs" http://localhost:5280/api/connected_users

但它总是返回 401 Unauthorized 错误.

But it always returns me 401 Unauthorized errors.

在我的 ejabberd.log 文件中,我有这个.

In my ejabberd.log file I have this.

2016-02-09 09:47:12.177 [info] <0.497.0>@ejabberd_listener:accept:333 (#Port<0.16419>) Accepted connection 127.0.0.1:62395 -> 127.0.0.1:5280
2016-02-09 09:47:12.177 [debug] <0.546.0>@ejabberd_http:init:154 S: [{[<<"websocket">>],ejabberd_http_ws},{[<<"oauth">>],ejabberd_oauth},{[<<"api">>],mod_http_api},{[<<"register">>],mod_register_web},{[<<"admin">>],ejabberd_web_admin},{[<<"http-bind">>],mod_http_bind}]
2016-02-09 09:47:12.177 [info] <0.546.0>@ejabberd_http:init:158 started: {gen_tcp,#Port<0.16419>}
2016-02-09 09:47:12.177 [debug] <0.546.0>@ejabberd_http:process_header:281 (#Port<0.16419>) http query: 'GET' <<"/api/connected_users">>
2016-02-09 09:47:12.177 [debug] <0.546.0>@ejabberd_http:process:353 [<<"api">>,<<"connected_users">>] matches [<<"api">>]
2016-02-09 09:47:12.178 [info] <0.546.0>@mod_http_api:log:388 Admin call connected_users [] from 127.0.0.1:62395

那么如何配置 Ejabberd 以允许 admin 用户请求所有 Ejabberd REST Web 服务?

So how to configure Ejabberd to allow the admin user to request all the Ejabberd REST Web Services ?

我的用户存储在 Mysql 中,因为 OAuth 令牌存储在 Mnesia 中,这可能是问题吗?

My users are stored in Mysql, as OAuth Tokens are stored in Mnesia could it be the problem ?

谢谢,

巴蒂斯特

推荐答案

确保输入正确的 User(jid): ( User (jid): user@hostname)

make sure you enter correct User(jid): ( User (jid): user@hostname)

它对我有用.

这篇关于Ejabberd OAuth/REST 401 未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆