Spring social login and redirect and return value

1.7k Views Asked by At

I am testing Spring Social Showcase and I wrote a similar application. While the Spring Social Showcase is a simple HTML application written using Spring MVC, my app is using angularjs and AJAX. There is a problem with redirection after access token is accepted by Twitter or Facebook.

In my flow, first I change the setting for ProviderSignInController:

providerSignInController.setSignUpUrl("/register/social"); <-- redirect into my controller

then there's my controller:

@RequestMapping(value="/social" ,method=RequestMethod.GET)
    public ModelAndView social(WebRequest request, ){
        LOG.info("Register new user using social info");
        Connection<?> connection = ProviderSignInUtils.getConnection(request);

        if(connection != null){
            LOG.info("User has been authorize from  " + connection.getKey().getProviderId());
            LOG.info("Connection class: " + connection.getClass());
            model.addAttribute("socialUser",RegisterUserDto.fromSocialProfile(connection.fetchUserProfile()) );
        }else{

        }

        return new ModelAndView("redirect:http://localhost:8080/turnigo-core-web/#/register");
    }

This controller is only redirecting me back to the website with the registration form, but I haven't got any user profile data from the social provider. The simple redirect is working fine, but it's not enough for my app. :/

I haven't got any idea how I can fix it, so here are my questions:

  1. It is possible to open social authentication website in another webpage, then close it and return to previous page with user profile data?

  2. Are there any examples with AJAX application using Spring Social login?

1

There are 1 best solutions below

0
On

I suggest to use SocialAuthenticationFilter instead of ProviderSignInController.SocialAuthenticationFilter gives full controller over spring security social login.Once social user is successfully logged in, then it is your wish to redirect to home page else to error page.

I have simple spring social login example which use SocialAuthenticationFilter to authenticate and to maintain connections with social providers.Hope it helps you.

Here is the example of how to implement social login feature using spring framework.Blog of this application for precise explination.