如何使用社交提供程序成功登录后设置重定向URL [英] How to set redirect url after success login using Social Providers
问题描述
当我的用户使用某些Spring Social Provider(例如Twitter)成功登录后,我需要更改重定向URL.
I need change the redirect url when my user is succefull logged in using some of Spring Social Providers, like Twitter in this case.
我正在获取每个set *** Url(")空指针异常 有时设置此项也不起作用
I'm getting in every set***Url("") a null pointer exception Some times setting this don't work too
我到目前为止尝试过设置:
I tried so far setting:
public ProviderSignInController signInController(ConnectionFactoryLocator connectionFactoryLocator,
UsersConnectionRepository usersConnectionRepository) {
ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator,
usersConnectionRepository,
new CSignInAdapter(requestCache()));
providerSignInController.setPostSignInUrl("/home");
providerSignInController.setApplicationUrl("localhost:8080/home");
return providerSignInController;
}
我分别尝试了setPostSignInUrl和setApplicationUrl中的每一个.
I tried each one of setPostSignInUrl and setApplicationUrl, separately.
也尝试过:
@Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
connectController.addInterceptor(new TweetAfterConnectInterceptor());
connectController.setApplicationUrl("/home");
return connectController;
}
我正在使用以Security为基础的Spring Social展示柜来完成此任务. 如果需要,我会发布HttpSecurity配置:
I'm using Spring Social showcase with Security as base to do this. In case of need I'm posting the HttpSecurity configuration:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/signin")
.loginProcessingUrl("/signin/authenticate")
.failureUrl("/signin?param.error=bad_credentials")
.defaultSuccessUrl("/home")
.and()
.csrf()
.and()
.logout()
.logoutUrl("/signout")
.deleteCookies("JSESSIONID")
.and()
.authorizeRequests()
.antMatchers("/admin/**", "/favicon.ico", "/resources/**", "/auth/**", "/signin/**", "/signup/**",
"/disconnect/facebook").permitAll()
.antMatchers("/**").authenticated()
.and()
.rememberMe()
.and()
.apply(new SpringSocialConfigurer());
}
推荐答案
尝试一下:
private SpringSocialConfigurer getSpringSocialConfigurer() {
SpringSocialConfigurer config = new SpringSocialConfigurer();
config.alwaysUsePostLoginUrl(true);
config.postLoginUrl("/home");
return config;
}
然后更改您的配置方法:
Then change your configure method:
.apply(getSpringSocialConfigurer());
这篇关于如何使用社交提供程序成功登录后设置重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!