我試圖在一個應用程序中將一個龐大的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
很高興你能夠自己解決它^^並通知我有關帖子:)我很好奇 –