gpt4 book ai didi

python - appengine 的 OAuth2 身份验证停止工作

转载 作者:行者123 更新时间:2023-12-01 03:57:41 25 4
gpt4 key购买 nike

我有一项定期工作,使用远程 API 从我的 appengine 数据存储中提取数据。这项工作突然停止工作,因为谷歌决定不再喜欢我的服务器。不过,它可以在我的机器上运行。

这是我机器上的 python shell 中发生的情况:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
<google.appengine.tools.appengine_rpc_httplib2.HttpRpcServerOAuth2 object at 0x7f5cdfac61d0>
>>>

这是我的服务器上相同代码发生的情况

(qmbi)dashboard@ip-172-31-32-222:~/qmbi$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.appengine.ext.remote_api import remote_api_stub
>>> app = 'qmagicobr2.appspot.com'
>>> remote_api_stub.ConfigureRemoteApiForOAuth(app, '/_ah/remote_api')
Go to the following link in your browser:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.apis+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=None&access_type=offline

Enter verification code:

当我访问上面的 URL 时,我收到一个错误页面,内容如下:

  1. That’s an error. Error: invalid_client The OAuth client was not found. Request Details access_type=offline scope=https://www.googleapis.com/auth/appengine.apis https://www.googleapis.com/auth/userinfo.email response_type=code redirect_uri=urn:ietf:wg:oauth:2.0:oob client_id=None That’s all we know.

帮忙?

---- 更新 (2016-05-12) -----

我忘了提及我正在使用的身份验证文件。为了使 ConfigureRemoteApiForOAuth 正常工作,我需要有一个环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向凭据文件。我愿意。在这两种环境(我的计算机和服务器)中,GOOGLE_APPLICATION_CREDENTIALS 都指向一个 json 文件(两种环境中的同一文件),格式如下:

{
"type": "service_account",
"project_id": "qmagicobr2",
"private_key_id": "000000000000000000000000000000000000000",
"private_key": "-----BEGIN PRIVATE KEY-----\nAAAAAAAAAAAAAAAAAAAAAAA....AAAA\n-----END PRIVATE KEY-----\n",
"client_email": "dashboard@qmagicobr2.iam.gserviceaccount.com",
"client_id": "0000000000000000000000",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dashboard%40qmagicobr2.iam.gserviceaccount.com"
}

此文件是使用 Appengine 的开发者控制台在“凭据/服务帐户 key /管理服务帐户”下生成的

最佳答案

所以我刚刚测试了这个特定的用例,客户端 id 为 none 的事实揭示了很多。

ConfigureRemoteApiForOAuth 接受使用带有 key 文件的服务帐号,以 appengine_rpc_httplib2.HttpRpcServerOAuth2.OAuth2Parameters 对象的形式提供 oauth2 参数,您可以在其中指定客户端 ID secret 范围OAuth2Parameters Doc

但是缓解这种情况的最简单方法是使用 gcloud tool正确验证您的服务器:

gcloud auth login

关于python - appengine 的 OAuth2 身份验证停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37148733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com