开发者

SocialAuthManager object ('manager') becomes NULL after redirection in case of SocialAuth libraries with JSF application?

开发者 https://www.devze.com 2023-03-28 06:26 出处:网络
I am using SocialAuth libraries in my JSF application for providing \'login with google/facebook\'. As shown below it requires me to stores the SocialAuthManager object (\'manager\') in the session an

I am using SocialAuth libraries in my JSF application for providing 'login with google/facebook'. As shown below it requires me to stores the SocialAuthManager object ('manager') in the session and then redirect to '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);

Then get the 'manager' from session on succssfull/failure redirection from facebook/redirect as shown below:

// 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();

The problem is if I am already logged in to facebook or google in a one of the 'tab' of the browser then this works perfectly OK. B开发者_如何学运维ut if I am not logged in already then session becomes NULL and consequently 'manager' as well.

In other words if redirection from 'my application to facebook to my application' happens then it fails. If I am already logged in to facebook then redirection does not happens and it works.

Can someone help? NOTE: this works perfectly well in case of IE but does not work in case of Chrome & Mozila


the reason for this behavior is that you are calling the redirected page from different domain so when page redirection happens your session data is lost. please have a look at this link

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

0

精彩评论

暂无评论...
验证码 换一张
取 消