2017-03-23 102 views
0

我想在我的應用程序中具有允許用戶授權Bitbucket的功能。我跟着https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html使用Node.js的Bitbucket OAuth2

下工作,並帶來如預期到位桶授權屏幕: https://bitbucket.org/site/oauth2/authorize?client_id=了{client_id} & RESPONSE_TYPE =代碼

然而,這部分發出有關無效格蘭特錯誤。

$ 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 
     } 
    } 

{ 「結果」:{ 「ERROR_DESCRIPTION」: 「不支持的授權類型:無」,「錯誤「:」invalid_grant「}}

請指教!

+1

是不是錯誤說你沒有在請求JSON中包含grant_type參數? –

+0

它應該是什麼? 如果我添加grant_type:「authorization_code」,它會投訴... {「result」:{「error_description」:「Unsupported grant type:None」,「error」:「invalid_grant」}} –

+0

@RickLee我試圖添加grant_type,但問題依然存在。 –

回答

1

找到了我的問題的答案。基本上,Bitbucket希望數據直接發送到主體而不是JSON。在上面的代碼中從json更改爲form爲我解決了這個問題。