这个谷歌文档网页,verify-google-id-token,说我应该使用Python模块google.oauth2和
google.auth.transport
来调用verify_oauth2_token api。
from google.oauth2 import id_token
from google.auth.transport import requests
# (Receive token by HTTPS POST)
# ...
def test():
try:
# Specify the CLIENT_ID of the app that accesses the backend:
idinfo = id_token.verify_oauth2_token("token", requests.Request(), "CLIENT_ID")
# Or, if multiple clients access the backend server:
# idinfo = id_token.verify_oauth2_token(token, requests.Request())
# if idinfo['aud'] not in [CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]:
# raise ValueError('Could not verify audience.')
# If auth request is from a G Suite domain:
# if idinfo['hd'] != GSUITE_DOMAIN_NAME:
# raise ValueError('Wrong hosted domain.')
# ID token is valid. Get the user's Google Account ID from the decoded token.
userid = idinfo['sub']
print("hello")
except ValueError:
# Invalid token
print("fail")
pass
if __name__ == '__main__':
test()
但是,当我在 Python 应用程序中引用这些模块时,我收到此错误:
错误:找不到满足 google.oauth2 要求的版本(来自版本:无) 错误:找不到 google.oauth2 的匹配发行版
这似乎表明该模块不存在。 当我首先引用 google.auth.transport 时,会发生同样的错误:
错误:找不到满足 google.auth.transport 要求的版本(来自版本:无) 错误:找不到 google.auth.transport 的匹配发行版
这些模块是受支持的还是我应该使用其他模块?
我尝试在我的requirements.txt 文件中引用这些模块,并期望它们能够被找到并加载。情况并非如此,所以我想知道应该使用哪些 Python 模块来解析引用的 api。
它对我来说工作正常,但我已经安装了所有这些软件包
你会不会少了一个?