19

有没有办法将另一个 OAuth2 提供程序与 Google Cloud Endpoints 一起使用?我的意思是,例如,从 Facebook 获取身份验证并以与我们使用 Google Account Auth 相同的方式使用它(使用 gapi js 并将 User 类放在@ApiMethod

4

4 回答 4

7

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

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 文档中找到有关自定义身份验证器的更多信息。

于 2014-12-13T09:22:47.287 回答
5

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

于 2013-04-08T14:52:40.807 回答
2

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

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

于 2014-04-20T03:12:22.237 回答
2

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

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

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

于 2015-06-11T17:40:48.360 回答