【问题标题】:EndPoints API authentification on GAE python with an Android client使用 Android 客户端在 GCP python 上进行 EndPoint API 身份验证
【发布时间】:2013-05-19 18:36:31
【问题描述】:

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

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

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

谢谢

【问题讨论】:

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


    【解决方案1】:

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

    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.')
    

    为此,您需要在 endpoints.api 装饰器或 endpoints.method 装饰器中为已验证的方法指定 audiences=allowed_client_ids=

    Endpoints auth docs 中描述了这些值。

    【讨论】:

    • 除此之外,请在此处查看 Python 后端的完整示例:github.com/GoogleCloudPlatform/…
    • 我相信例子应该是raise endpoints.UnauthorizedException('Invalid token.')
    • 谢谢!我改了。
    猜你喜欢
    • 1970-01-01
    • 2013-06-06
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2019-01-07
    • 1970-01-01
    • 2022-10-30
    相关资源
    最近更新 更多