【问题标题】:Google Cloud Endpoints with another oAuth2 providerGoogle Cloud Endpoints 与另一个 oAuth2 提供程序
【发布时间】:2013-03-30 03:07:12
【问题描述】:

是否可以通过 Google Cloud Endpoints 使用其他 OAuth2 提供程序?我的意思是,例如,从 Facebook 获取身份验证并像使用 Google Account Auth 一样使用它(使用 gapi js 并将 User 类放在 @ApiMethod 上)

【问题讨论】:

标签: google-app-engine oauth-2.0 facebook-oauth google-cloud-endpoints


【解决方案1】:

Google Cloud Endpoints 允许您将 User、HttpServletRequest 和 HttpServletContext 作为参数注入到您的 API 方法中。

这不是 OAuth2,但这是解决方案的开始: https://www.yanchware.com/custom-authentication-for-google-cloud-endpoints/

建议的解决方案是在特定的api方法中注入HttpServletRequest来访问会话。

【讨论】:

    【解决方案2】:

    您必须实现自己的Authenticator 并更新@Api 配置。基于此answer,一个简单的身份验证器将如下所示:

    public class MyAuthenticator implements Authenticator {
    
        @Override
        public User authenticate(HttpServletRequest request) {
            String token = request.getHeader("Authorization");
            if (token != null) {
                // apply your Facebook/Twitter/OAuth2 authentication
                String user = authenticate(token);
                if (user != null) {
                    return new User(user);
                }
            }
            return null;
        }
    }
    

    还有你的 API 定义

    @Api(name = "example", authenticators = {MyAuthenticator.class})
    

    您可以在Google documentation 中找到有关自定义身份验证器的更多信息。

    【讨论】:

    • 有python等价物吗?
    • @JanuszSkonieczny 我不知道它是否可用于 python,你应该问一个关于 SO 的新问题
    • 有人知道如何将数据放在android客户端的标头中吗?
    【解决方案3】:

    我编写了一个示例,将 Facebook 访问令牌交换为我的应用程序生成的令牌,并从端点方法中对其进行验证:

    https://github.com/loudnate/appengine-endpoints-auth-example

    【讨论】:

      【解决方案4】:

      没有。我遇到其他人问这个问题,谷歌人的回答(如果我没记错的话)是端点用户身份验证目前只支持谷歌帐户。

      【讨论】:

      • 有没有办法实现替代方案?就像在会话中存储用户一样? (我刚刚发现该会话在 Google Cloud Endpoint 中也不起作用)
      • 当然,您可以实现任何您想要的替代方案,并且您可以通过端点传递系统的令牌,但您必须自己实现身份验证。
      • 这里的问题是如何控制用户会话,因为Google Endpoint不提供会话,对吧?
      • 是的,这是我的理解。
      • @InsaurraldeAP 这不是真的。您可以实现自己的身份验证架构,也可以通过其他提供商实现 OAuth。
      猜你喜欢
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 2018-11-06
      相关资源
      最近更新 更多