带有Google提供商的Spring OAuth2客户端不断请求身份验证 [英] Spring Oauth2 client with Google provider keep asking for authentication
本文介绍了带有Google提供商的Spring OAuth2客户端不断请求身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个Spring Oidc客户端应用程序。我按如下方式配置OAuth2客户端:
spring:
security:
oauth2:
client:
registration:
google:
client-id: my_client_id
client-secret: my_secret
clientName: myapp
redirectUri: 'http://localhost:8081/wellcome'
WebSecurityConfigurerAdapter
....
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login();
}
在http://localhost:8081/wellcome上配置了重定向URL
在我初始化身份验证后,客户端重定向到Google身份验证页面,它继续请求身份验证。 如果我保留默认重定向URL(即../OAuth2/code/google),则应用程序运行正常。
如果我使用不同的重定向URL,为什么重定向不能正常工作?
推荐答案
默认重定向URI为/login/oauth2/callback/{registrationId}
。
重定向到/login/oauth2/callback/{registrationId}
时,OAuth2LoginAuthenticationFilter
将处理请求,尝试对用户进行身份验证并创建OAuth2AuthenticationToken
。
通过更改重定向URI,OAuth2LoginAuthenticationFilter
不会被调用,并且应用程序不知道用户是否已通过身份验证,这就是它提示用户再次进行身份验证的原因。
您可能正在尝试更改defaultSuccessUrl
。
这指定用户在身份验证成功后将重定向到何处。
http
.oauth2Login(oauth2Login -> oauth2Login
.defaultSuccessUrl("/welcome")
)
这篇关于带有Google提供商的Spring OAuth2客户端不断请求身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文