Как отправить oauth2.0 id_token в заголовок http? Неверная ошибка заполнения - PullRequest
0 голосов
/ 18 июня 2019

Я пытаюсь отправить googleId и id_token в заголовок http. По какой-то причине я не могу проверить токен из-за неправильной ошибки заполнения. Я следую этому руководству: https://developers.google.com/identity/sign-in/web/backend-auth

Я попытался скопировать строку id_token в мой код (заменив переменную request_user_id_token), и verify_oauth2_token работает просто отлично. Есть проблема, потому что я читаю это из заголовка http.

Я также напечатал значение request_user_id_token, и оно точно соответствует ожидаемому.

@app.before_request
def before_request():

try:
    request_user_id = request.headers.get('google-id')
    request_user_id_token = request.headers.get('google-id-token')

    if not (request_user_id and request_user_id_token):
        raise ValueError('Missing id and id token in request headers')


    # THIS LINE THROWS
    id_token.verify_oauth2_token(request_user_id_token, requests.Request(), os.environ.get("ELEVATE_GOOGLE_CLIENT_ID"))

    print(google_id_info)
    if google_id_info['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
        raise ValueError('Wrong issuer.')

    # ID token is valid. Get the user's Google Account ID from the decoded token.
    google_user_id = int(google_id_info['sub'])

    if request_user_id != google_user_id:
        raise ValueError('The supplied google id does not match the supplied id token')

# Authentication Error (Incliding Expired Token)
except ValueError as error:
    print(error)
    pass

При выводе ошибки в конце просто выводится «Неверное заполнение»

...