Spring Boot OAuth2 не вызывает успех и всегда перенаправляет на «/» после аутентификацииJAVA

Программисты JAVA общаются здесь
Anonymous
Spring Boot OAuth2 не вызывает успех и всегда перенаправляет на «/» после аутентификации

Сообщение Anonymous »

Я пытаюсь настроить базовую настройку Google Oauth для приложения Spring Boot. Моя идея заключается в том, что Frontend будет перенаправлен на URL, такой как http: // localhost: 8081/oauth2/woruthization/Google, и после аутентификации бэкэнд создает пользователя, пользовательский сеанс затем перенаправляет на Localhost: 3000 (Frontend)
Я написал oauth2successhesshandler и oauthrahdrahandfaird hare hare hare hare -and. SecurityConfig. < /P>

Код: Выделить всё

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final OAuth2SuccessHandler successHandler;
private final OAuth2FailureHandler failureHandler;

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeHttpRequests(auth -> auth
.requestMatchers("/oauth2/**","/auth/**").permitAll()
.anyRequest().authenticated()
)
.oauth2Login(oauth -> oauth
.successHandler(successHandler)
.failureHandler(failureHandler)
);
return http.build();
}

}
< /code>
В основном, кажется, работает, однако после аутентификации OAuth2SuccessHandler не вызывается. Похоже, это < /p>
@Component
@RequiredArgsConstructor
public class OAuth2SuccessHandler implements AuthenticationSuccessHandler {

@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response,
Authentication authentication) throws IOException {
//My logic
}
}
< /code>
"моя логика" никогда не выполняется. Аутентификация кажется успешной, я могу увидеть данные своей учетной записи Google в журналах. После этого он перенаправляется на «/» (Localhost: 8081/) вместо того, чтобы перейти к моему обработчику успеха. 
В случае Application.properties полезен, 
spring.security.oauth2.client.registration.google.client-id=
spring.security.oauth2.client.registration.google.client-secret=
spring.security.oauth2.client.registration.google.scope=openid,email,profile
spring.security.oauth2.client.registration.google.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}

spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
spring.security.oauth2.client.provider.google.user-info-uri=https://openidconnect.googleapis.com/v1/userinfo
spring.security.oauth2.client.provider.google.user-name-attribute=sub
Мой вопрос заключается в том, чтобы понять, почему мой успех не используется и как это исправить.

Подробнее здесь: https://stackoverflow.com/questions/796 ... ects-to-af

Вернуться в «JAVA»