Google 客户端 API verify_oauth2_token 应使用哪个 Python 模块

问题描述 投票:0回答:1

这个谷歌文档网页,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。

python google-oauth google-api-python-client
1个回答
0
投票

它对我来说工作正常,但我已经安装了所有这些软件包

  • google-api-core 2.11.0
  • google-api-python-客户端 2.62.0
  • 谷歌验证2.17.3
  • 谷歌-auth-httplib2 0.1.0
  • google-auth-oauthlib 0.5.3
  • googleapis-common-protos 1.56.4

你会不会少了一个?

© www.soinside.com 2019 - 2024. All rights reserved.