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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Edited

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 Jan 03, 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

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

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

@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

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?

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.

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

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

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
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,741 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you