使用Android客户端在GAE python上进行EndPoints API身份验证

时间:2013-05-24 07:57:09

标签: android google-app-engine authentication python-2.7 google-cloud-endpoints

我希望我的Android应用程序能够与我的应用引擎服务器进行通信。我希望只有经过身份验证的用户(谷歌用户)才能访问我的EndPoints Api并使用PYTHON存储在appengine中。

这里有一个使用java appengine的例子:
https://developers.google.com/eclipse/docs/endpoints-addauth

我想在服务器端使用User对象并将其另存为,而不是仅保存电子邮件地址。 例如,protorpc的请求对象将:
MessageRequest(用户用户,......)
当用户在应用程序中使用谷歌帐户登录时,如果它是一个有效的谷歌帐户,他将填充用户对象(在服务器上),如果它不是一个好的帐户,他将无法访问API。

谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用endpoints库在Python中执行相同的操作:

from google.appengine.ext import endpoints

@endpoints.api(...)
class MyApi(...):

    @endpoints.method(...)
    def my_method(self, request):
        current_user = endpoints.get_current_user()
        if current_user is None:
            # This will result in a 401
            raise endpoints.UnauthorizedException('Invalid token.')

要执行此操作,您需要在audiences=装饰器或allowed_client_ids=装饰器中为经过身份验证的方法指定endpoints.apiendpoints.method

这些值在Endpoints auth docs

中描述
相关问题