Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Failure to connect to Bitbucket cloud from another system.

Shad
Contributor
July 27, 2021

I am trying to connect to my bitbucket cloud workspace from another system (XL Release) using Oauth2. I have created a client ID and secret key as per the instructions (https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)

When attempting to connect I am getting the following error on XL Release:

Can't connect to Bitbucket Cloud.

Exception: HTTP response code 401 (Unauthorized)

I have provided the Access token URL as https://bitbucket.org/site/oauth2/access_token

I am not sure if I am missing anything.

Documentation is not clear and also there is no option to check the logs to see if I am able to hit the Bitbucket URL or not.

Any help would be appreciated.

Thanks a lot.

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Caroline R
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 30, 2021

Hi, @Shad!  

Thank you for reaching out to Atlassian Community!

Before anything, I would like to share with you all the steps to get the Access token, just to confirm you have followed the right process:

  • Access the workspace and click on Settings;

  • Click OAuth consumersAdd consumer;

  • Add at least the following information:

    • Name

    • Callback URL

    • The Permissions you want to give to this OAuth

  • Click Save;

  • Access the link:

    https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code
  • Replace the "{client_id}" with the Key generated on your OAuth

  • Click on Grant Access

  • You will be redirected to a URL that will contain a code (You will see something like this: code=XXXX on the URL)

  • Then, run the following code, replacing the Key and secret with the information on your OAuth (set in your workspace), and the code generated on the URL in the last step:

    curl -X POST -u <Key:Secret> https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code=<Insert the code here>
  • Then, you should receive an output that contains the token, something like this:

  • {"scopes": "pullrequest:write repository:delete pipeline:variable snippet:write project:write webhook team:write issue:write account:write wiki", "access_token": "XXXXXXX", "expires_in": 7200, "token_type": "bearer", "state": "authorization_code", "refresh_token": "XXX"}%
  • This will give you the Access token to authenticate.

  • If you would like to test this token, you can use the Access token to authenticate the following API:

    curl -X GET https://api.bitbucket.org/2.0/repositories --header ‘authorization: Bearer <insert the token here>’

If you follow all the steps mentioned above and face any issues, please share the error you received, and in case you need help in this process, I’ll be glad to assist you. 

Kind regards,
Caroline

Shad
Contributor
August 23, 2021

Thank you very much Caroline.

I have a couple of follow-up question:

1. Does the token obtained using this process expire in 7200 seconds? If yes, what can be done to reuse it for longer time? When I created this token and used it to connect from the Digital.ai Release, it gives me a message that it was able to connect/authenticate successfully. And the same token continues to show a successful connection even after days of creating it.

To test if this is a false message while the token may actually expiring, when I change the token even by one character it fails to connect. So does it mean it is still active?

2. The other question I have is how to identify the Repository path if my account is a company account? In case of accounts created using personal email IDs, the path of the repository would be "TeamName/Repository" or "Username/Repository". In case of a company owned account, would the repository path be WorkspaceName/ProjectName/RepositoryName ? 

Any guidance would be much appreciated!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events