【发布时间】:2017-05-28 05:46:40
【问题描述】:
我正在尝试将一个整体 Google App Engine 应用程序(使用 Python 和标准环境)拆分为一个应用程序中的多个服务。默认服务是调用另一个服务中使用 Endpoints 框架实现的 API。
除了我不明白如何正确检查默认服务的身份验证(并使其在本地开发服务器和生产环境中都工作)之外,一切都很好。
调用我使用的服务google-api-python-client 和默认应用程序凭据。
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
service = build(
name, version,
credentials=GoogleCredentials.get_application_default(),
discoveryServiceUrl=discovery_url)
service.client_token().execute()
我的服务 API 代码如下所示
@endpoints.api(
name='test',
version='v1',
)
class TestApi(remote.Service):
@endpoints.method(
message_types.VoidMessage,
TestResponse,
path='test',
http_method='GET',
name='test')
def get_test(self, request):
# user = endpoints.get_current_user()
# if not user:
# raise endpoints.UnauthorizedException
return TestResponse(test='test')
在生产中endpoints.get_current_user() 似乎返回了正确的应用程序用户,但我不知道如何正确验证它是同一个应用程序。在本地开发环境中endpoints.get_current_user() 返回None。
【问题讨论】:
-
您的问题解决了吗? :) 我很好奇你是否这样做
-
@KingReload 是的,事实证明这是一件相当简单的事情。我必须生成招摇文件并部署它。今天晚些时候我会尝试发布详细的答案。
-
很高兴您能够自行解决 ^^ 并通知我该帖子:) 我很好奇
标签: google-app-engine oauth-2.0 google-cloud-endpoints microservices google-oauth