我试图在一个应用程序中将一个庞大的Google App Engine应用程序(使用Python &标准环境)拆分为多个服务。默认服务是调用使用另一个服务中的端点框架实现的API。如何检查Google Cloud Endpoints中的服务到服务认证?
除了我不明白如何正确检查默认服务的身份验证(并使其在本地开发服务器和生产环境中均可用)之外,一切都很好。
要调用我使用的服务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是的,它原来是一个相当简单的事情。我必须生成swagger文件并部署它。我会尽量在今天晚些时候发布详细的答案。 – Fedor
很高兴你能够自己解决它^^并通知我有关帖子:)我很好奇 –