简体   繁体   English

Google Cloud Endpoints:身份验证问题(错误403)

[英]Google Cloud Endpoints: Authentication issues (error 403)

I'm trying to connect to my Google Cloud Endpoints API that is running as an Appengine app: 我正在尝试连接到作为Appengine应用程序运行的Google Cloud Endpoints API:

@endpoints.api(name='helloworldendpoints', allowed_client_ids=["1234", "12345"], version='v1', auth_level=endpoints.AUTH_LEVEL.REQUIRED)
class HelloWorldApi(remote.Service):
...

The API request is as follows: API请求如下:

scopes = ["https://www.googleapis.com/auth/userinfo.email"]
credentials = ServiceAccountCredentials.from_json_keyfile_name("CloudEndpointsClient.json", scopes)

from httplib2 import Http
http_auth = credentials.authorize(Http())

from apiclient.discovery import build

api_root = 'https://myapp.appspot.com/_ah/api'
api = 'helloworldendpoints'
version = 'v1'
discovery_url = '%s/discovery/v1/apis/%s/%s/rest' % (api_root, api, version)
service = build(api, version, discoveryServiceUrl=discovery_url)


response = service.myFunction(myparameter = "123456").execute(http=http_auth)#
print response

The requests work well if I remove authentication requirements. 如果我删除身份验证要求,则这些请求可以很好地工作。 I know that authentication works since the error changes if after authenticating. 我知道身份验证有效,因为如果经过身份验证,错误就会更改。

The error message I'm getting is: 我收到的错误消息是:

googleapiclient.errors.HttpError: https://my-app.appspot.com/_ah/api/helloworldendpoints/v1/obtainScoreFromEmail?myparameter=1234&alt=json returned "Access Not Configured. has not been used in project 123456789 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/helloworldendpoints/overview?project=123456789 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."> googleapiclient.errors.HttpError:https://my-app.appspot.com/_ah/api/helloworldendpoints/v1/obtainScoreFromEmail?myparameter=1234&alt=json返回了“未配置访问权限。之前未在项目123456789中使用,否则已禁用。请访问https://console.developers.google.com/apis/api/helloworldendpoints/overview?project=123456789启用它,然后重试。如果您最近启用了此API,请等待几分钟,以便该操作传播到我们的系统并重试。“>

I cannot enable the API in my Google Cloud Project, since the API does not exist. 由于该API不存在,因此无法在我的Google Cloud Project中启用该API。

What I found to work is a hack around. 我发现工作很简单。 I used a user authentication (instead of server) on the same project for the same API which worked ( https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python ). 我在同一项目中使用了用户身份验证(而非服务器身份验证)来使用相同的API( https://cloud.google.com/endpoints/docs/frameworks/python/access_from_python )。

After I switched back to my initial server auth. 在切换回我的初始服务器身份验证之后。 method it started working. 它开始起作用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM