【问题标题】:Bitbucket OAuth2 using Node.js使用 Node.js 的 Bitbucket OAuth2
【发布时间】: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


【解决方案1】:

找到了我的问题的答案。基本上,Bitbucket 期望数据直接以正文而不是 JSON 形式发送。在上面的代码中从json 更改为form 为我修复了它。

【讨论】:

    猜你喜欢
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2019-07-15
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2012-08-01
    相关资源
    最近更新 更多