簡體   English   中英

使用Node.js的Bitbucket OAuth2

[英]Bitbucket OAuth2 using Node.js

我想在我的應用程序中具有允許用戶授權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
      }
  }

{“結果”:{“ error_description”:“不支持的授予類型:無”,“錯誤”:“ invalid_grant”}}

請指教!

找到了我問題的答案。 基本上,Bitbucket希望數據直接在正文中發送,而不是JSON。 從上面的代碼中的json更改為form對我來說已經修復了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM