Skip to content

Instantly share code, notes, and snippets.

@israelb
Last active August 4, 2017 20:22
Show Gist options
  • Save israelb/b26dc05e3e33f0ed3464da2ffacf548b to your computer and use it in GitHub Desktop.
Save israelb/b26dc05e3e33f0ed3464da2ffacf548b to your computer and use it in GitHub Desktop.
To manipulate Bitbucket repository with token:
First you create an "Oauth" in access management section of your bitbucket account setting. This gives you a "Key" and a "Secret". You have done this bit.
Now using these Key and Secret you ask Bitbucket for a token. In my case I made a http request to https://bitbucket.org/site/oauth2/access_token. I could do it with Curl or some Ajax library like this:
curl -X POST -u "yourKeyHere:yourSecretHere" https://bitbucket.org/site/oauth2/access_token -d grant_type=client_credentials
alternatively, my http request was like this (using superagent in node) with my Content-Type set to application/x-www-form-urlencoded you can use postman:
request.post("https://yourKeyHere:[email protected]/site/oauth2/ access_token").send('grant_type=client_credentials');`
the result is like this:
{
"access_token": "blah blah blah HXAhrfr8YeIqGTpkyFio=",
"scopes": "pipeline snippet issue pullrequest project team account",
"expires_in": 3600,
"refresh_token": "hsadgsadvkQ",
"token_type": "bearer"
}
Now that you have the "access_token", clone a private repo with it. But the url to your repo should be like this (keep the bracket around token):
https://x-token-auth:{tokenHere}@bitbucket.org/yourRepoOwnerHere/RepoNameHere.git
example for gem
gem 'yourGem', git: "https://x-token-auth:[email protected]/yourRepo.git"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment