如何在Spring Webflow中为OAuth2定制登录页面? [英] How Can I Customize Login Page for Oauth2 in Spring Webflux?
本文介绍了如何在Spring Webflow中为OAuth2定制登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/login
)。我怎么能这么做呢?我尝试的配置没有成功:
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
http
.authorizeExchange().pathMatchers(permittedUrls).permitAll()
.anyExchange().authenticated()
.and()
.oauth2Login(Customizer.withDefaults()).formLogin().loginPage("/oauth2_login")
.authenticationSuccessHandler(this::onAuthenticationSuccess)
.and()
.csrf().disable();
return http.build();
我希望它将重定向到/oauth2_login
URL,但它不起作用。它仍然重定向到/LOGIN。但这一次它返回404,而不是显示默认登录页面。
推荐答案
上面的代码是为formLogin
定制登录页面,通常是基于用户名/密码从表单登录。使用新的lambda样式方法可以更容易地看到您正在影响的配置,所以我已经更新了整个配置以使用它。如果您想要为oauth2Login定制登录页面,那么您应该在上面更改登录页面。例如:
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
http
.authorizeExchange(exchanges -> exchanges
.pathMatchers(permittedUrls).permitAll()
.anyExchange().authenticated()
)
.oauth2Login(oauth2 -> oauth2
// you now must render a log in page for the URL /login
.loginPage("/login")
);
// remove formLogin that was for a username/password based log in
// if you are doing oauth2 login I'm guessing you allow users to work within a browser, so you should not disable csrf
return http.build();
}
这篇关于如何在Spring Webflow中为OAuth2定制登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文