Please go here and authorize bitbucket

I am trying to download files from a private repo with bitbucket. I am using oauth 2 and following this guide: https://developer.atlassian.com/blog/2016/02/bitbucket-oauth-with-python/

It seems to get stop at: redirect_response = raw_input('Paste the full redirect URL here:') and I get:

Please go here and authorize: https://bitbucket.org/site/oauth2/authorize?response_type=code&client_id=&state=WDWADWADWADWADWDA
https://api.bitbucket.org/2.0/repositories/Tysondogerz/more/downloads: https://api.bitbucket.org/2.0/repositories/Tysondogerz/more/downloads

How do I authenticate this so it runs? New to bitbucket and can't find much on this

 

Code:

from requests_oauthlib import OAuth2Session
class ClientSecrets:
    '''
    The structure of this class follows Google convention for `client_secrets.json`:
    https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
    Bitbucket does not emit this structure so it must be manually constructed.
    '''
    client_id = "32313123123123"
    client_secret = "321d12e2131312323"
    redirect_uris = [
      "https://api.bitbucket.org/2.0/repositories/Tysondogerz/more/downloads"  # Used for testing.
    ]
    auth_uri = "https://bitbucket.org/site/oauth2/authorize"
    token_uri = "https://bitbucket.org/site/oauth2/access_token"
    server_base_uri = "https://api.bitbucket.org/"


def main():
    c = ClientSecrets()
    # Fetch a request token
    bitbucket = OAuth2Session(c.client_id)
    # Redirect user to Bitbucket for authorization
    authorization_url = bitbucket.authorization_url(c.auth_uri)
    print('Please go here and authorize: {}'.format(authorization_url[0]))
    # Get the authorization verifier code from the callback url
    redirect_response = input('Paste the full redirect URL here: 
https://api.bitbucket.org/2.0/repositories/Tysondogerz/more/downloads')
    # Fetch the access token
    bitbucket.fetch_token(
      c.token_uri,
      authorization_response=redirect_response,
      username=c.client_id,
      password=c.client_secret)
    # Fetch a protected resource, i.e. user profile
    r = bitbucket.get(c.server_base_uri + '1.0/user')
    print(r.content)

if __name__ == '__main__':
    main()

 

0 answers

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,049 views 1 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you