How to set redirect url after success login using Social Providers

 ̄綄美尐妖づ 提交于 2019-11-30 21:35:51

Try this:

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

        return config;
}

Then change your configure method:

.apply(getSpringSocialConfigurer());

For Spring Social, you can configure the post login URL to a default URL, such as "/home".

But under certain circumstances, you would like to direct the user to a different URL. In order to dynamically change the redirect URL after successful login, you can simply return a String representing any URL you desire in the signIn method of your SignInAdapter implementation class:

import org.springframework.social.connect.web.SignInAdapter;

public class SocialSignInAdapter implements SignInAdapter {

    public String signIn(String localUserId, Connection<?> connection, NativeWebRequest request) {
        boolean flag = true;
        if (flag) {        
            return "/a_different_url";
        }
        return null; // Default, which means using the default post login URL
    }
}

I verified this using Spring Social version 1.1.0.RELEASE

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!