Skip to content

Instantly share code, notes, and snippets.

@tigranl

tigranl/test.py Secret

Last active December 1, 2016 16:47
Show Gist options
  • Save tigranl/f6725c2d6e76dab891f3447bd34f3ed6 to your computer and use it in GitHub Desktop.
Save tigranl/f6725c2d6e76dab891f3447bd34f3ed6 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_access_token(data={'code': code, 'redirect_uri': redirect_uri,
'grant_type': 'authorization_code', 'token_type': 'bearer'},
decoder= lambda a: json.loads(a.decode('utf-8')))
return session.get('oauth2/token').json()
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