谷歌云端点与另一个oAuth2提供商
有没有办法在Google云端点上使用另一个OAuth2提供商?我的意思是,例如,从Facebook获取身份验证,并使用它与我们使用Google帐户身份验证的相同方式(使用gapi js并将用户类别放在@ApiMethod
上)谷歌云端点与另一个oAuth2提供商
不,我遇到了其他人询问此问题以及谷歌人(如果我没记错的话)是端点用户身份验证目前仅支持Google帐户。
有没有一种方法来实现替代?就像在会话中存储用户一样? (我刚刚发现该会话在Google Cloud Endpoint中也不起作用) – 2013-04-08 15:41:06
当然,您可以实现您想要的任何替代方法,并且可以通过端点传递系统的令牌,但是您必须自己实施身份验证。 – Tom 2013-04-08 15:51:41
这里的问题是如何控制用户会话,因为Google Endpoint没有提供会话,对吗? – 2013-04-08 16:32:25
我写了一个例子交换了一个由我的应用程序生成的Facebook的访问令牌,并从端点方法中验证它:
https://github.com/loudnate/appengine-endpoints-auth-example
你必须实现自己的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 Cloud Endpoints允许您将User,HttpServletRequest和HttpServletContext作为参数注入API方法中。
它不是的OAuth2但这里是一个解决方案的begining: https://www.yanchware.com/custom-authentication-for-google-cloud-endpoints/
所提出的解决方案是注入的HttpServletRequest在特定的API方法来访问会话。
看看这个:http://stackoverflow.com/questions/18716674/facebook-login-in-google-cloud-endpoints/22495862#22495862 – 2014-04-03 16:04:14