我正在尝试在我的微服务应用中实现google登录,其中API-Gateway位于端口8080上,用于处理google登录的UAA服务位于端口3001上。我遵循了本教程https://www.callicoder.com/spring-boot-security-oauth2-social-login-part-2/,但我仍然坚持回调网址。
所以问题出在->
我能够在http:// localhost:8080 / auth / oauth / authorize / google?redirect_uri = http:// localhost:8080 / auth / test上触发授权流
然后,我选择我的Google帐户,并重定向到回调URL http:// localhost:8080 / auth / oauth / callback,但是此后,我没有重定向到指定的URL_uri,我只得到Callback result image这个错误。
注释
在调试期间,我注意到从DefaultOAuth2UserService重写的loadUser方法的自定义实现未调用。同样,我的successHandler和failureHandler的实现也不会调用。
这是我的bootstrap.yml:
security:
oauth2:
client:
registration:
google:
clientId: <myClientId>
clientSecret: <mySecret>
redirectUri: http://localhost:8080/auth/oauth/callback
scope:
- email
- profile
这是我在UAA服务中的securityConfig方法:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().
authorizeRequests().
antMatchers("/auth/**").permitAll()
.and()
.oauth2Login()
.authorizationEndpoint()
.baseUri("/auth/oauth/authorize")
.authorizationRequestRepository(httpCookieOAuth2AuthorizationRequestRepository)
.and()
.redirectionEndpoint()
.baseUri("/auth/oauth/callback/*")
.and()
.userInfoEndpoint()
.userService(customOauthUserDetailsService)
.and()
.successHandler(oAuth2AuthenticationSuccessHandler)
.failureHandler(oAuth2AuthenticationFailureHandler);
}