gpt4 book ai didi

java - 成功登录 google oauth2 时出现重定向错误

转载 作者:行者123 更新时间:2023-12-02 01:33:16 25 4
gpt4 key购买 nike

我正在使用 Spring Security 来实现 google oauth2 客户端,并在成功登录后,而 google 授权服务器正在重定向,获取页面未正确重定向。

@Configuration
@EnableWebSecurity
@EnableOAuth2Client
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override protected void configure(HttpSecurity http) throws Exception {

http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
.failureUrl("/login?error")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("http://www.google.com")
.and()
.oauth2Client();
}
}
<小时/>
# oauth2 client configuration
spring:
security:
oauth2:
client:
registration:
google:
provider: google
clientId:
client-secret:
authorization-grant-type: authorization_code
redirect-uri: http://localhost:8090/home
scope: openid,profile,email
provider:
google:
authorization-uri: https://accounts.google.com/o/oauth2/v2/auth
token-uri: https://oauth2.googleapis.com/token
user-info-uri: https://openidconnect.googleapis.com/v1/userinfo
user-name-attribute: sub
jwk-set-uri: https://www.googleapis.com/oauth2/v3/certs

server:
port: 8090

Google 控制台

google console

Application.yml

Application.yml

浏览器错误

browser error

最佳答案

默认情况下,基本重定向 URI 为:/oauth2/code/{registrationId}

所以你的重定向 uri 应该是:http://localhost:8090/login/oauth2/code/google

如果你想改变它,你可以在redirectionEndpoint上进行例如

.oauth2Login()
.redirectionEndpoint()
.baseUri("your custom redirect uri")

关于java - 成功登录 google oauth2 时出现重定向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57543100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com