Google -Authentifizierungsproblem im Spring Start: Fehler integrieren OAuth2 in Google [geschlossen]Java

Java-Forum
Anonymous
 Google -Authentifizierungsproblem im Spring Start: Fehler integrieren OAuth2 in Google [geschlossen]

Post by Anonymous »

Ich entwickle derzeit eine Rast -API mit Spring Boot. Ich konnte die grundlegende Authentifizierung mit JWT abschließen. Ich habe versucht, es mit OAuth2 für Google und andere soziale Netzwerke zu tun, und es zeigte mir, dass dieser Fehler: < /p>
Ein unerwarteter Fehler ist nicht aufgerufen. Moment, ich habe diese Konfiguration in der Umleitungs -URL in Google -Konsole:
http: // localhost: 8080/oATH2/Erfolg y http: // localhost: 8080/login/oATH2/code/google/google csrf.disable () // Desactiva csrf Si No. />. RequestMatchers ("/api/v1/auth/", "/oauth2/"). Genehmigung () // Permite Acceso a rutas de autenticación youth2
. Anyrequest (). />.SessionManagement(Session -> Sitzung
/>.DefaultSuccessurl("/oAuth2/success ", true) // Redirige A ESTA URL Después de un login exitoso
.FailureUrl("/login?error=true") // Redirige si ocurre unfehler en el login
> >>> >>>>>>>>>> >>>>> >>>> userfoenfo -userfo -lofo -login
> >>>>>>>> userin />.oidCuSerService(New oidcuserservice ()) // configura el servicio para obtener la información del useuario de google
)
)
.AuthenticationProvider(AuthenticationProvider) // Añade teedor de Autenticación -Personizadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoadoado und. />.AddFilterBefore(jwtauthenticationFilter, usernamepasswordAuthenticationFilter.class) // Agrega el filtro jwt Antes del filro de autenticación de useuario y contraseña
.build();br />} < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> < /p> @Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

// configuration.setAllowedOrigins(List.of("http://localhost:8080"));
configuration.setAllowedMethods(List.of("GET","POST"));
configuration.setAllowedHeaders(List.of("Authorization","Content-Type"));

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

source.registerCorsConfiguration("/**",configuration);

return source;
}
}
< /coe>
Meine API für oAuth2 Ich habe es so: < /p>
@RestController
@RequestMapping("/oauth2")
public class Oauth2Controller {
private final JwtService jwtService;
private final AuthenticationService authenticationService;
private final UserService userService;

public Oauth2Controller(JwtService jwtService, AuthenticationService authenticationService, UserService userService) {
this.jwtService = jwtService;
this.authenticationService = authenticationService;
this.userService = userService;
}
@GetMapping("/success")
public Map user(@AuthenticationPrincipal DefaultOAuth2AuthenticatedPrincipal principal) {
Map userInfo = Collections.singletonMap("name", principal.getAttribute("name"));
return userInfo;
}
}
< /code>
Ich hoffe, Sie können mir helfen, weil ich eine Weile festgefahren bin. Grüße.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post