【发布时间】:2015-02-19 23:03:09
【问题描述】:
我已经使用 Google App Engine 构建了一个与 Web 客户端通信的自定义端点 API,并且我已经成功地使用 API Explorer 和 Web 客户端对其进行了测试。
现在我正在尝试通过这些instructions 使用web client ID 向云端点API 添加身份验证。我可以让身份验证工作,但无法让身份验证成为必需。
WEB_CLIENT_ID = # Some Client ID
@endpoints.api(name="AppApi", version="v1", allowed_client_ids=[WEB_CLIENT_ID], audiences=[WEB_CLIENT_ID], scopes=[endpoints.EMAIL_SCOPE])
class AppApi(remote.Service):
@endpoints.method(TestRequestMessage, TestResponseMessage, name="test.get", path="test/get")
def TestGet(self, request):
response = TestResponseMessage()
# Return a blank response message
return response
我故意尝试在 allowed_client_ids 中排除 endpoints.API_EXPLORER_CLIENT_ID,因为我想确保它对于未通过 API Explorer 进行身份验证的请求会失败。
不过,当我转到 API 资源管理器时,我可以在没有身份验证的情况下发出成功的请求。当我使用 API 资源管理器打开身份验证时,它会要求我启用电子邮件身份验证,这样就可以了,但它不需要对调用进行身份验证。
如何让 Google Cloud Endpoints API 要求每次调用都进行身份验证?
我也没有使用 API 做任何用户特定的工作,所以我只是尝试使用 Web 客户端凭据来使用 Web 客户端身份验证,以便它是 Web 客户端请求信息。没有用户登录。
【问题讨论】:
标签: python google-app-engine google-oauth google-cloud-endpoints