我在我的 JSF 应用程序中使用 SocialAuth 库来提供“使用 google/facebook 登录”。如下所示,它需要我将 SocialAuthManager 对象('manager')存储在会话中,然后重定向到 'google/facebook' URL
//Create an instance of SocialAuthManager and set config
SocialAuthManager manager = new SocialAuthManager();
manager.setSocialAuthConfig(config);
// URL of YOUR application which will be called after authentication
String successUrl= "http://opensource.brickred.com/socialauthdemo/socialAuthSuccessAction.do";
// get Provider URL to which you should redirect for authentication.
// id can have values "facebook", "twitter", "yahoo" etc. or the OpenID URL
String url = manager.getAuthenticationUrl(id, successUrl);
// Store in session
session.setAttribute("authManager", manager);
然后从 facebook/redirect 的成功/失败重定向会话中获取“经理”,如下所示:
// get the social auth manager from session
SocialAuthManager manager = (SocialAuthManager)session.getAttribute("authManager");
// call connect method of manager which returns the provider object.
// Pass request parameter map while calling connect method.
AuthProvider provider = manager.connect(SocialAuthUtil.getRequestParametersMap(request));
// get profile
Profile p = provider.getUserProfile();
问题是,如果我已经在浏览器的“标签”之一中登录了 facebook 或 google,那么这完全可以。但是,如果我尚未登录,则会话变为 NULL,因此也变为“经理”。
换句话说,如果发生从“我的应用程序到 facebook 到我的应用程序”的重定向,那么它就会失败。如果我已经登录到 facebook,则不会发生重定向并且可以正常工作。
有人可以帮忙吗?注意:这在 IE 的情况下工作得很好,但在 Chrome 和 Mozila 的情况下不起作用