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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.