Example #1
0
def process():
    body = request.json
    if 'api' in body:
        endpoint = body['api']
        if endpoint == 'login':
            api = Mobileclient()
            flow = oauth2client.client.OAuth2WebServerFlow(
                **api._session_class.oauth._asdict())
            url = flow.step1_get_authorize_url()
            return {'url': url}
        elif endpoint == 'new_releases':
            api = Mobileclient(validate=False)
            credentials = oauth2client.client.OAuth2Credentials.from_json(
                body['creds'])
            api._authtype = 'oauth'
            api.session.login(credentials)
            albums = get_albums(api)
            return {'albums': albums}
    elif 'auth' in body:
        code = body['auth']
        api = Mobileclient()
        flow = oauth2client.client.OAuth2WebServerFlow(
            **api._session_class.oauth._asdict())
        credentials = flow.step2_exchange(code)
        string_creds = credentials.to_json()
        return {'creds': string_creds}
    return ''