我正在构建一个登录模块,您可以使用各种社交网络帐户进行登录。第一步是LinkedIn和谷歌。
LinkedIn部分运行良好,但Google部分运行不正常,我认为问题出在身份验证之前的代码,因为返回的url有openid参数,而不是OAuth参数。这是重定向之前的代码:
HttpSession session = request.getSession();
SocialAuthConfig config = SocialAuthConfig.getDefault();
try {
config.load("/oauth_consumer.properties");
} catch (Exception ex) {
System.out.println(ex);
}
//Create an instance of SocialAuthManager and set config
SocialAuthManager manager = new SocialAuthManager();
try {
manager.setSocialAuthConfig(config);
} catch (Exception ex) {
System.out.println(ex);
}
//URL of YOUR application which will be called after authentication
String successUrl = "http://localhost:8080/ProjectName/completelogin.do";
String url = "";
try {
url = manager.getAuthenticationUrl(type, successUrl).toString();
} catch (Exception ex) {
System.out.println(ex);
}
// Store in session
session.setAttribute("authManager", manager);
response.sendRedirect(url);这是我为谷歌提供的oauth_consumer.properties部分
www.google.com.consumer_key = 81XXXXXX466.apps.googleusercontent.com
www.google.com.consumer_secret = WN0oXXXXXXXHoCeSocQK
www.google.com.custom_permissions=https://www.googleapis.com/auth/userinfo.profile,https://www.googleapis.com/auth/userinfo.email我可以强制谷歌使用OAuth身份验证来代替OpenID身份验证吗?我用另一个使用OAuth的框架登录了谷歌,它工作得很棒。只是现在,因为我想使用几个社交网站,所以我不想一直重复发明轮子,只使用socialauth…
发布于 2013-03-29 05:45:05
Google身份验证端点是https://accounts.google.com/o/openid2/auth,OAuth2端点是/o/oauth2/auth。您需要将终端用户重定向到OAuth2端点,以告知(或“强制”)谷歌使用OAuth2。
发布于 2015-03-19 01:52:38
作者:https://github.com/3pillarlabs/socialauth/wiki/Sample-Properties
如果需要或需要传递额外参数,可以设置OAuth端点(RequestToken URL、授权URL和AccessToken URL
https://stackoverflow.com/questions/15665050
复制相似问题