我正在尝试使用 OAuth 1.0a 授权我使用服务。我可以执行requestToken
和authorize
步骤,但是当我调用accessToken
URL 时,我会收到401 Unauthorized响应并返回以下消息:
OAuth Verification Failed: Can't exchange request token "THE_TOKEN" for access token. No such token or not authorized%
我已经掩盖了凭据和 URL。
请求令牌 URL:https
://url-to-the-service.com/oauth/requestToken
授权令牌 URL:https
://url-to-the-service.com/oauth/authorize
访问令牌 URL:https:// url-to-the-service.com/oauth/accessToken
我从服务中获得的凭据如下:
consumer_key = CONSUMER_KEY
consumer_secret = CONSUMER_SECRET
第 1 步 - 请求临时令牌
curl -v -X GET --url "https://url-to-the-service.com/oauth/requestToken?oauth_version=1.0& \
oauth_timestamp=1516721112& \
oauth_nonce=25794& \
oauth_signature_method=PLAINTEXT& \
oauth_consumer_key=CONSUMER_KEY& \
oauth_signature=CONSUMER_SECRET%26"
然后服务响应:
oauth_callback_confirmed=true&oauth_token=THE_TOKEN&oauth_token_secret=THE_TOKEN_SECRET&xoauth_token_ttl=3600
第 2 步 - 使用临时令牌授权我并获得验证者
然后我在浏览器中输入:
https://url-to-the-service.com/oauth/authorize?oauth_token=THE_TOKEN
...它提示我登录服务。当我在登录后按下授权按钮时,我被转发到此 URL:
https://url-to-the-service.com/oauth/authorize?yes=1&oauthVerifier=123456789&oauth_token=THE_TOKEN
第 3 步 - 请求访问令牌
最后,我https://url-to-the-service.com/oauth/accessToken
通过将oauth_verifier
和令牌秘密添加到oauth_signature
:
curl -v -X GET --url "https://url-to-the-service.com/oauth/accessToken?oauth_version=1.0& \
oauth_timestamp=1516730938& \
oauth_nonce=30888& \
oauth_signature_method=PLAINTEXT& \
oauth_consumer_key=CONSUMER_KEY& \
oauth_signature=CONSUMER_SECRET%26THE_TOKEN_SECRET& \
oauth_token=THE_TOKEN& \
oauth_verifier=123456789"
但服务响应:
OAuth Verification Failed: Can't exchange request token "THE_TOKEN" for access token. No such token or not authorized%
那么我错过了什么?