简体   繁体   中英

Spring Social Login redirect after successful url

I have spring boot application with social login. I have followed spring-social-showcase example to get social login working. But now I have problem with redirect URL after successful authentication. Signup page works fine. I have configured SpringSecurity as follows:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .apply(getSpringSocialConfigurer())
            .and()
            .formLogin()
            .loginPage("/")
            .and()
            .logout()
            .deleteCookies("JSESSIONID")
            .and()
            .authorizeRequests()
            .antMatchers("/admin/**", "/favicon.ico", "/resources/**", "/auth/**", "/signin/**", "/signup/**", "/disconnect/facebook", "/").permitAll()
            .antMatchers("/**").authenticated()
            .and()
            .rememberMe()
            .and()
            .csrf().disable();
}

private SpringSocialConfigurer getSpringSocialConfigurer() {
    SpringSocialConfigurer config = new SpringSocialConfigurer();
    config.alwaysUsePostLoginUrl(true);
    config.postLoginUrl("/profile?login=true");

    return config;
}

@Bean
public SocialUserDetailsService socialUserDetailsService() {
    return new SimpleSocialUserDetailsService(userDetailsService());
}

Move your SocialConfigurer under .formLogin, it sets the default target url correctly but is then overwritten in form auth.

http
        .formLogin()
        .loginPage("/")
        .and()
        .apply(getSpringSocialConfigurer())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM