【问题标题】:Admin Oauth authentication in EjabberdEjabberd 中的管理员 Oauth 身份验证
【发布时间】:2022-01-12 23:26:12
【问题描述】:

我是 Ejabberd 和 Erlang 的新手,我很难理解为什么我只能使用 GET 方法而不是 POST 进行身份验证。

我可以使用 GET (https://myserver/oauth/authorization_token?response_type=token&client_id=Client1&redirect_uri=http://client.uri&scope=ejabberd:admin) 成功进行身份验证,它会打开一个我将在凭据并提交,它会将我重定向到http://client.uri/?access_token=VuzKqO55OZoCFp45lBkapLis3dsMGKB7&token_type=bearer&expires_in=31536000&scope=ejabberd:admin&state= 之类的网址。

问题是,我不想使用网络表单,我想直接从我的应用程序中使用 API,但是我不允许直接使用 POST 方法,即使 Ejabberd 在幕后使用了这种方法。

我可以在ejabberd_oauth.erl这两种方法中看到它。

process(_Handlers,
    #request{method = 'GET', q = Q, lang = Lang,
         path = [_, <<"authorization_token">>]})

process(_Handlers,
    #request{method = 'POST', q = Q, lang = _Lang,
         path = [_, <<"authorization_token">>]}) 

我不明白为什么 GET 可以访问而 POST 不能访问。

【问题讨论】:

    标签: api rest oauth ejabberd


    【解决方案1】:

    我不允许直接使用POST方法

    你的意思是这样的吗?

    我首先按照标准程序,嗅探 HTTP 流量。然后我写了一个小shell脚本直接执行POST:

    call.sh 的浓度:

    CONTENT='username=user1%40localhost&password=asd&response_type=token&client_id=Client1&redirect_uri=http%3A%2F%2Fclient.uri&scope=get_roster+sasl_auth&state=&ttl=31536000'
    
    curl -v -k -X POST -H "Content-type: application/x-www-form-urlencoded" \
         -d "${CONTENT}" "http://localhost:5280/oauth/authorization_token"
    

    结果:

    ❯ ./call.sh
    ...
    < Location: http://client.uri?access_token=4Vh9Ib9JOJYFvUILjzNouNlrkWRIsgs8&token_type=bearer&expires_in=31536000&scope=get_roster sasl_auth&state=
    ...
    

    https://docs.ejabberd.im/developer/ejabberd-api/oauth/#authorization-token 中所述,获取令牌的更复杂方法是​​使用 oauth_issue_token ejabberd 命令。为此,您必须启用 ReST 或 ejabberd_xmlrpc,并且您必须限制权限,因为这样可以访问所有 ejabberd。

    【讨论】:

    • 谢谢,尝试从 Postman 发出相同请求时出现问题。像你一样做卷曲,奏效了。
    • 实际上邮递员有一个内部错误,因为响应是重定向,我没有注意到。我将redirect_uri 设置为postman-echo.com/get,现在我可以在json 中获得响应。
    猜你喜欢
    • 2020-09-30
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 2014-10-08
    • 2013-07-10
    • 2018-12-05
    • 2011-01-11
    • 2019-07-16
    相关资源
    最近更新 更多