google-app-engine - 与另一个 oAuth2 提供商的 Google Cloud Endpoints

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

有没有办法将另一个 OAuth2 提供商与 Google Cloud Endpoints 一起使用?我的意思是,例如,从 Facebook 获取身份验证并像我们使用 Google Account Auth 一样使用它(使用 gapi js 并将用户类放在 @ApiMethod 上)

最佳答案

您必须实现自己的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 中找到.

关于google-app-engine - 与另一个 oAuth2 提供商的 Google Cloud Endpoints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872240/

相关文章:

node.js - Firebase 身份验证与云 sql 混合

android - 何时用刷新 token 交换访问 token

node.js - Passport-Facebook 不提供电子邮件,即使它在范围内

c# - 在 asp net 中从 facebook 获取用户电子邮件

java - 无法在 Eclipse 中创建 GWT Web 应用程序项目

jquery - 带有 jquery 的 Django 模板 : Ajax update on existing page

java - 使用 Spray 访问 GAE 数据存储

php - OAuth2.0 Server栈如何使用state来防止CSRF?对于 draft2.0 v20

Spring Security 5 OAuth2 客户端与 Gitlab 失败

facebook - HWIOAuthBundle是否支持检索好友列表、性别、国家