使用 Google 进行端点 API 身份验证

Endpoints API authentication with Google

我想对发送到我的 api 的请求进行身份验证,使其成为一个有效的 google 帐户。

@endpoints.api(name='echo', 
           version='v1',
           allowed_client_ids=[API_EXPLORER_CLIENT_ID,
                               "*****-************.apps.googleusercontent.com"],
           auth_level=AUTH_LEVEL.REQUIRED)
class EchoApi(remote.Service):
    @endpoints.method(
                    # This method takes a ResourceContainer defined above.
                    ECHO_RESOURCE,
                    # This method returns an Echo message.
                    EchoResponse,
                    path='echo',
                    http_method='POST',
                    name='echo',
                    api_key_required=True)
    def echo(self, request):
        print endpoints.get_current_user()
        print request
        output_content = ' '.join([request.content] * request.n)
        return EchoResponse(content=output_content)

上面是我实现的代码,如果我未经授权发送请求header请求仍然到达后端

你必须检查是否 get_current_user() returns None.

auth_level 在此版本的框架中实际上没有做任何事情。