1

I want to have a capability in my application that allows users to Authorize Bitbucket. I have followed https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html.

The following works and brings the Bitbucket authorization screen as expected: https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code

However, this part emits an error about invalid Grant.

$ curl -X POST -u "client_id:secret" \ https://bitbucket.org/site/oauth2/access_token \ -d grant_type=authorization_code -d code={code} 

I am using request module in Node.js and using the code as follows:

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":"Unsupported grant type: None","error":"invalid_grant"}}

Please advice!

3
  • 1
    isn't the error saying u haven't included the grant_type parameter in your request JSON? Commented Mar 23, 2017 at 8:22
  • What should it be? If I add grant_type: "authorization_code" it complains... {"result":{"error_description":"Unsupported grant type: None","error":"invalid_grant"}} Commented Mar 23, 2017 at 11:16
  • @RickLee I tried adding the grant_type, but the issue persists. Commented Mar 23, 2017 at 11:32

1 Answer 1

3

Found the answer to my question. Basically, Bitbucket expects data to be sent in body directly instead of JSON. Changing from json to form in the code above fixed it for me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.