Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from requests_oauthlib import OAuth2Session
- class ClientSecrets:
- client_id = "<ClientId>"
- client_secret = "<Secret key>"
- redirect_uris = [
- "https://localhost/" # Used for testing.
- ]
- auth_uri = "https://bitbucket.org/site/oauth2/authorize"
- token_uri = "https://bitbucket.org/site/oauth2/access_token"
- server_base_uri = "<restserver>"
- 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 =
- "<callback link>"
- # 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 + 'explorer/')
- print(r.content)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment