我是 Ejabberd 和 Erlang 的新手,我很難理解為什么我只能使用 GET 方法而不是 POST 進行身份驗證。
我可以使用 GET (https://myserver/oauth/authorization_token?response_type=token&client_id=Client1&redirect_uri=http://client.uri&scope=ejabberd:admin) 成功進行身份驗證,它會打開一個 Web 表單,我將輸入我的憑據并提交它會將我重定向到像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 不是。
uj5u.com熱心網友回復:
我不允許直接使用 POST 方法
你的意思是這樣的嗎?
我首先按照標準程式,嗅探 HTTP 流量。然后我寫了一個小shell腳本直接執行POST:
call.sh 的濃度:
CONTENT='username=user1@localhost&password=asd&response_type=token&client_id=Client1&redirect_uri=http://client.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。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409929.html
標籤:
