Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

hot to git clone with oauth? how to create token for this kind of use?

Dennis December 10, 2017

Is not clear here... how to create the access token,

Any help is appreciated.

2 answers

1 accepted

1 vote
Answer accepted
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 3, 2018

Hi Dennis, cloning with OAuth looks like:

$ git clone https://x-token-auth:{access_token}@bitbucket.org/user/repo.git

The string x-token-auth is required as a substitute for the username.

OAuth needs a key and secret, which together are know as an OAuth consumer. To create a consumer, do the following:

  1. In your Bitbucket account, navigate to your avatar in the bottom left and click Bitbucket settings.
  2. In the left navigation panel, click OAuth > Add consumer.  
    The system will ask you for name, description, callback URL and URL.

  3. Click Save. The system generates a key and a secret for you.
  4. Toggle the consumer name to see the generated Key and Secret value for your consumer.

Let us know if you have any more questions or if you're stuck somewhere.

Best regards,

Ana

Amir Koklan February 25, 2018

what should we do with that Key and Secret then ? in the URL you are talking about access_token and then you are giving us Key and Secret ?


The best would be if you can make a example URL of how it looks like

thanks

Like Mohsen Kamrani likes this
Néstor Acevedo April 14, 2018

An excessive incomplete @Ana Retamal's answer.

The OAuth credentials are easy to create, but the auth_token is what you have never touched.

Like # people like this
Néstor Acevedo April 14, 2018

@Amir Koklanfor generating the token you can use your consumer key as key in the following address:

https://bitbucket.org/site/oauth2/authorize?client_id={key}&response_type=token

It will ask you for permissions according what you have chosen on creating the consumer.

In the URL you will find the access token that you can use later in

git clone https://x-token-auth:{access_token}@bitbucket.org/user/repo.git
Nikolas Pitsillos July 12, 2018

Can you please explain how to access that URL?  I am new to this and I am trying to build a script that declines a PR but I need the OAuth.  I have the key and secret how to I use that URL to get the token?

Néstor Acevedo August 29, 2018

Is mandatory to create the OAuth2 credentials accessing to your accout.

Follow the steps in https://community.atlassian.com/t5/Bitbucket-questions/Re-hot-to-git-clone-with-oauth-how-to-create-token-for/qaq-p/697127/comment-id/21947#M21947

 

The callback URL can be any URL; you can use http://example.com.

 

When you call https://bitbucket.org/site/oauth2/authorize?client_id={key}&response_type=token (the key value for client_id is your OAuth consumer key), you will find the callback url with the params sent by BitBucket. One of these params is the access token.

babak houman June 12, 2019

Thanks for all your support. Here is a step by step description of the process which worked for me.

I just copied and pasted a selection of all the steps mentioned above (also from other threads) and tried to make a recipe. 

 

# How to generate/use bitbucket API key

first go to https://bitbucket.org/account/user/HoChiMinh/api and create a
new consumer (you can use https://example.com as callBackUrl if necessary).


OAuth needs a key and secret, which together are know as an OAuth consumer. To create a consumer, do the following:

1. In your Bitbucket account, navigate to your avatar in the bottom left and click Bitbucket settings.
2. In the left navigation panel, click OAuth > Add consumer.
3. The system will ask you for name, description, callback URL and URL.
4. Click Save. The system generates a key and a secret for you.
Toggle the consumer name to see the generated Key and Secret value for your consumer.

 

then:
```

> request:
curl -X POST -u "$key:$secret" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials

> reponse:
{"access_token": "$APIKEY", "scopes": "snippet issue team pullrequest project wiki pipeline webhook", "expires_in": 7200, "refresh_token": "$REFRESH_TOKEN", "token_type": "bearer"}

> test:
git clone "https://x-token-auth:$APIKEY@bitbucket.org/$user/$repo"

```

Like # people like this
xcli March 25, 2020

Is it correct that APIKEY expires at some interval ? Can one APIKEY be used permanently ?

2 votes
gildas_cherruel April 20, 2020

I know this is a fairly old thread, but, just in case, I wrote my own credential store to manage bitbucket's token:

https://github.com/gildas/git-credential-bitbucket

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events