首页 文章

没有Google帐户的Google Cloud endpoints

提问于
浏览
12

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

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

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

2 回答

  • 1

    你不需要做任何事情 . 我在app-engine上有一个联合登录应用程序,我最近添加了一个使用Cloud Endpoints的Android应用程序 . 您不必执行任何特殊操作,只需将User参数添加到您的函数中即可 . 在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
        }
    }
    

    创建 endpoints 后,请访问:https://your-app.appspot.com/_ah/api/explorer并测试它

    UPDATED: The example above is restricted to Google accounts . 如果您想要一个不同类型的帐户,可以查看这篇文章:Custom Authentication for Google Cloud Endpoints (instead of OAuth2)

  • 0

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

    事实上, endpoints 只是http请求,因此您可以传递http授权的信息,如持票人 . 您可以完全访问 endpoints 的此信息信息 .

    我希望它会对你有所帮助 .

相关问题