Guest User

Untitled

a guest
Jun 7th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import requests
  2. from requests_oauthlib import OAuth2Session
  3.  
  4. class ClientSecrets:
  5. client_id = "<ClientId>"
  6. client_secret = "<Secret key>"
  7. redirect_uris = [
  8. "https://localhost/" # Used for testing.
  9. ]
  10. auth_uri = "https://bitbucket.org/site/oauth2/authorize"
  11. token_uri = "https://bitbucket.org/site/oauth2/access_token"
  12. server_base_uri = "<restserver>"
  13.  
  14. def main():
  15. c = ClientSecrets()
  16. # Fetch a request token
  17. bitbucket = OAuth2Session(c.client_id)
  18. # Redirect user to Bitbucket for authorization
  19. authorization_url = bitbucket.authorization_url(c.auth_uri)
  20. print('Please go here and authorize: {}'.format(authorization_url[0]))
  21. # Get the authorization verifier code from the callback url
  22. redirect_response =
  23. "<callback link>"
  24. # Fetch the access token
  25. bitbucket.fetch_token(
  26. c.token_uri,
  27. authorization_response=redirect_response,
  28. username=c.client_id,
  29. password=c.client_secret)
  30. # Fetch a protected resource, i.e. user profile
  31. r = bitbucket.get(c.server_base_uri + 'explorer/')
  32. print(r.content)
  33.  
  34. if __name__ == '__main__':
  35. main()
Add Comment
Please, Sign In to add comment