1

I need to create an HTTP access token for a repository which allows me to pull modules from it while building a nodeJS application in another repository.

This was done in the past by using a personal access token from one of the employees and I want to change that.

I refered to this article " https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html " in which the steps are stated as follows:

Create HTTP access tokens for projects or repositories

HTTP access tokens can be created for teams to grant permissions at the project or repository level rather than for specific users. To create an HTTP access token for a project or repository (requires project or repository admin permissions):

  1. From either the Project or Repository settings, select HTTP access tokens.
  2. Select Create token.
  3. Set the token name, permissions, and expiry.

The problem is in my repository settings, I can't find "HTTP access tokens".

I'm using Bitbucket cloud whereas the article refers to bitbucket Server, does that make a problem? If so, this option isn't available in bitbucket cloud?

daveruinseverything
  • 4,775
  • 28
  • 40
Bl4ckMED
  • 104
  • 1
  • 1
  • 6

3 Answers3

7

Atlassian has vast documentation, but I have a problem with it and still don't understand how to get an access token to be able simply download archives from private repositories.

So here is my step by step tutorial

  1. Insert your workspace name instead of {workspace_name} and go to the following link in order to create an OAuth consumer
https://bitbucket.org/{workspace_name}/workspace/settings/api
  • set callback URL to http://localhost:8976 (doesn't need to be a real server there)
  • select permissions: repository -> read
  1. use consumer's Key as a {client_id} and open the following URL in the browser
https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code
  1. after you press "Grant access" in the browser it will redirect you to
http://localhost:8976?code=<CODE>

Note: you can spin your local server to automate this step

  1. use the code from the previous step and consumer's Key as a {client_id}, and consumer's Secret as {client_secret}:
curl -X POST -u "{client_id}:{client_secret}" \
  https://bitbucket.org/site/oauth2/access_token \
  -d grant_type=authorization_code \
  -d code={code} \
  1. you should receive similar json back
{
  "access_token": <access_token>,
  "scopes": "repository",
  "token_type": "bearer",
  "expires_in": 7200,
  "state": "authorization_code",
  "refresh_token": <refresh_token>
}
  1. use the access token in the following manner
curl https://api.bitbucket.org/2.0/repositories/{workspace_name} \
--header "Authorization: Bearer {access_token}
Mikolasan
  • 626
  • 10
  • 19
1

Whilst your question is about Bitbucket Cloud, the article you linked is for Atlassian's self-hosted source control tool Bitbucket Server. They have different functionality for different use cases, which is why they don't look the same.

Depending on your use case you can use App passwords or OAuth instead.

Full disclosure: I work for Atlassian

daveruinseverything
  • 4,775
  • 28
  • 40
  • Once you get the token, what do you do with it? I'm on a mac. – Adrian Aug 23 '22 at 20:58
  • Google Dataform only allows secret manager with personal token to be used. Any suggestions how to connect to bitbucket, it works seemlessly with Git. – RaptorX Nov 18 '22 at 12:21
0

Easiest way to do it is:

  1. Create an OAuth consumer in your Bitbucket settings (also provide dummy redirect like localhost:3000, copy KEY and SECRET.
  2. Use curl -X POST -u "KEY:SECRET" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials to get JSON data with access-token.
zygimantus
  • 3,649
  • 4
  • 39
  • 54