【问题标题】:Google Cloud Endpoints without Google Accounts没有 Google 帐户的 Google Cloud Endpoints
【发布时间】:2013-10-14 00:28:41
【问题描述】:

我们的网络应用程序不提供 Google 帐户身份验证。我们已经使用 WebApp2 身份验证实现了自己的身份验证:http://webapp-improved.appspot.com/tutorials/auth.html

我们希望将 Cloud Endpoints 用作移动应用程序/第三方开发人员的 API,但我们仍希望使用 oAuth2 进行身份验证。

实现这一点需要哪些步骤?我们是否需要在 AppEngine 上设置我们自己的 oAuth 服务器,并且 Google 客户端库是否兼容?

【问题讨论】:

    标签: google-app-engine authentication google-cloud-endpoints


    【解决方案1】:

    你不需要做任何事情。我在 app-engine 上有一个联合登录应用程序,我最近在其中添加了一个使用 Cloud Endpoints 的 Android 应用程序。您不必做任何特别的事情,只需将 User 参数放入您的函数中。在用户对象中,您将找到您必须授权才能访问数据的用户电子邮件。

    @Api(name = "my_api",
            version = "v1",
            scopes = {"https://www.googleapis.com/auth/userinfo.email"},
            clientIds = {Constants.AUTH_CLIENT,
                    Constants.AUTH_CLIENT_APIEXPLORER})
    public class MyEndpoint {
        @ApiMethod(name = "fistEndpoint")
        public ResponseObject fistEndpoint(User user) throws OAuthRequestException {
            if (user == null) {
                throw new OAuthRequestException("Access denied!");
            }
            String email = user.getEmail();
            //Authorize the request here
            //make the ResponseObject and return it
        }
    }
    

    创建端点访问后: https://your-app.appspot.com/_ah/api/explorer 测试一下

    更新: 以上示例仅限于 Google 帐户。如果您想要其他类型的帐户,可以查看此帖子: Custom Authentication for Google Cloud Endpoints (instead of OAuth2)

    【讨论】:

      【解决方案2】:

      Google Cloud Endpoints 是无状态的,因此如果您不使用 Google 身份验证,则无法将用户电子邮件检索到端点中。

      实际上,端点只是 http 请求,因此您可以将您的信息传递给 http 授权,就像不记名一样。您可以完全访问这些端点信息。

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-29
        • 1970-01-01
        • 2018-12-18
        • 1970-01-01
        • 1970-01-01
        • 2015-07-13
        • 2013-05-23
        • 1970-01-01
        相关资源
        最近更新 更多