【发布时间】:2017-08-15 15:44:52
【问题描述】:
我希望我的应用程序具有允许用户授权 Bitbucket 的功能。我关注了https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html。
以下工作并按预期显示 Bitbucket 授权屏幕: https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code
但是,这部分会发出关于无效授权的错误。
$ curl -X POST -u "client_id:secret" \
https://bitbucket.org/site/oauth2/access_token \
-d grant_type=authorization_code -d code={code}
我在Node.js中使用request模块,使用代码如下:
request.post(
'https://bitbucket.org/site/oauth2/access_token',
{
json: {
client_id: config.get('app.bitbucket_client_id'),
client_secret: config.get('app.bitbucket_client_secret'),
code: req.query.code,
grant_type: "authorization_code"
}
}, function (error, response, body) {
// Do something here
}
}
{"result":{"error_description":"不支持的授权类型:无","error":"invalid_grant"}}
请指教!
【问题讨论】:
-
错误不是说你的请求 JSON 中没有包含 grant_type 参数吗?
-
应该是什么?如果我添加 grant_type: "authorization_code" 它会抱怨... {"result":{"error_description":"Unsupported grant type: None","error":"invalid_grant"}}
-
@RickLee 我尝试添加grant_type,但问题仍然存在。
标签: node.js oauth-2.0 bitbucket