예제 #1
0
def _authorization_code_request(auth_code):
    config = read_config()
    auth_key = get_auth_key(config.client_id, config.client_secret)
    headers = {'Authorization': f'Basic {auth_key}', }
    options = {
        'code': auth_code,
        'redirect_uri': 'http://localhost:3000/callback',
        'grant_type': 'authorization_code',
        'json': True
    }

    response = requests.post(
        config.access_token_url,
        headers=headers,
        data=options
    )
    content = json.loads(response.content.decode('utf-8'))

    if not response.ok:
        error_description = content.get('error_description')
        raise BadRequestError(error_description)

    access_token = content.get('access_token', None)
    token_type = content.get('token_type', None)
    expires_in = content.get('expires_in', None)
    refresh_token = content.get('refresh_token', None)
    scope = content.get('scope', None)

    return Authorization(access_token, token_type, expires_in, scope, refresh_token)
예제 #2
0
def _authorization_code_request(auth_code):
    config = read_config()

    auth_key = get_auth_key(config.client_id, config.client_secret)

    headers = {"Authorization": "Basic {}".format(auth_key), }

    options = {
        'code': auth_code,
        'redirect_uri': "http://localhost:3000/callback",
        'grant_type': 'authorization_code',  # This is important to getting authorization to change permissions
        "json": True
    }

    response = requests.post(
        config.access_token_url,
        headers=headers,
        data=options
    )

    content = json.loads(response.content.decode('utf-8'))

    if response.status_code ==400:
        error_description = content.get("error_description", "")
        raise BadRequestError("error_description")

    access_token =content.get('access_token', None)
    token_type = content.get("token_type", None)
    expires_in = content.get("expires_in", None)
    scope = content.get("scope", None)
    refresh_token = content.get("refresh_token", None)

    return Authorization(access_token, token_type, expires_in,
                         scope, refresh_token)