Skip to content

Instantly share code, notes, and snippets.

@tigranl

tigranl/test.py Secret

Created November 29, 2016 20:12
Show Gist options
  • Save tigranl/edcdb8b9f7770d0d918ab14273724fa6 to your computer and use it in GitHub Desktop.
Save tigranl/edcdb8b9f7770d0d918ab14273724fa6 to your computer and use it in GitHub Desktop.
from rauth import OAuth2Service
import json
def auth(client_id, secret, scope):
global service, redirect_uri
service = OAuth2Service(
client_id=client_id,
client_secret=secret,
authorize_url="https://musicbrainz.org/oauth2/authorize",
access_token_url="https://musicbrainz.org/oauth2/token",
base_url="https://musicbrainz.org/"
)
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
params = {'response_type': 'code',
'scope': scope,
'redirect_uri': redirect_uri}
url = service.get_authorize_url(**params)
return url
def get_info(code):
session = service.get_auth_session(data={'code': code, 'redirect_uri': redirect_uri,
'grant_type': 'authorization_code'},
decoder=lambda data: json.loads(data.decode('utf-8')))
try:
return session.get('oauth2/userinfo').json()
except:
return "Failed to fetch user profile"
print(auth("qLYLK0LlrhifkgXq0N-J4w", "XPiJdmSkh6uJDoWguo-J7g", "profile"))
print(get_info(input()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment