我正在尝试在http标头中发送googleId和id_token。由于某些原因,由于填充错误,我无法验证令牌。 我正在遵循此指南: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
最后打印错误只会输出“不正确的填充”