对于带有JSF应用程序的SocialAuth库,重定向后SocialAuthManager对象('manager')变为NULL?

时间:2011-08-12 17:16:13

标签: jsf jsf-2 socialauth

我在我的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中获取succssfull / failure重定向会话中的'manager',如下所示:

// 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和&amp ;;的情况下不起作用。 Mozila

1 个答案:

答案 0 :(得分:0)

此行为的原因是您从不同的域调用重定向的页面,因此当页面重定向发生时,会话数据将丢失。 请看一下这个链接

http://31stdimension.blogspot.in/2012/04/how-to-connect-facebook-using-jsfjava.html