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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,658
Community Members
 
Community Events
176
Community Groups

Accessing a bit bucket repo form java sdk

Edited

Hi Team,

I am trying clone a git repo from out side using https://client_id:secret@bitrepourl.git:develop, though i have oauthcosumer i am getting invalid authentication error 

Am I referring it wrongly 

 

Regards,

Sangameshwar

1 answer

0 votes

Hi Sangameshwar,

Could you please confirm if this is a Bitbucket Cloud repo (https://bitbucket.org/)?

If so, the client and secret of the OAuth consumer cannot be used for cloning.
You will need to generate an access token using the key and secret, and then use this access token to clone as follows:

git clone https://x-token-auth:{access_token}@bitbucket.org/<workspace-id>/<repo-slug>.git

 

I am listing below the step to generate an access token for an OAuth consumer:

1. First, create an OAuth consumer (I assume you have already done this, so you can skip that step).
Make sure that the consumer has a Callback URL, you can use http://localhost

 

2. Then in your browser address bar enter the following URL
(replace {consumer_key} with the key of your consumer, no brackets in the URL):

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

When you hit Enter, the URL will be like the following:

http://localhost/?code=fpYPDYsryEpsRawrj4

Copy the code in the response, in this example it is fpYPDYsryEpsRawrj4

 

3. You can then obtain an access token by executing the following command in terminal

curl -X POST -u "key:secret" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code=fpYPDYsryEpsRawrj4

Replace key with your consumer's key
Replace secret with your consumer's secret
Replace the code value in there (fpYPDYsryEpsRawrj4) with your code from the previous step


4. You can use the access token that you obtained from the previous step, to clone a repo, as follows:

git clone https://x-token-auth:{access_token}@bitbucket.org/<workspace-id>/<repo-slug>.git

Replace access_token with your access_token from the previous step, but leave the brackets in the URL.
The literal string x-token-auth as a substitute for username is required.


5. Our access tokens expire in two hours. When this happens you'll get 401 responses.

You will have to use the refresh token from the output in step 3 to get a new access token.

curl -X POST -u "key:secret" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={2Eoiw6UJ707AD9aIyUR}

Replace key with the consumer's key
Replace secret with the consumer's secret
Replace the value of the refresh_token in the example I gave (2Eoiw6UJ707AD9aIyUR) with the one from the output of step 3

The output of the above command will give you a new access token (with the same 2 hour expiry) and also a refresh token.


Please feel free to let me know how it goes and if you have any questions.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events