Cześć, próbuję dodać logowanie do mojej strony przez google api,
trochę kodu:
//na tym endpoincie logujemy sie przez gogole
@GetMapping("/google/login")
public Principal get(Principal prince){
return prince;
}
//pomocniczy enpoint
@GetMapping("/user")
public String get(){
return "Zwrócono Stringa";
}
//po zalogowaniu przez google
@GetMapping("/after")
public String getAfter(){
return "Zostałeś zalogowany przez Google API :)";
}
WebSecurityConfig
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/google/login").authenticated();
}
application.properties
security.oauth2.client.clientId=***
security.oauth2.client.clientSecret=***
security.oauth2.client.accessTokenUri=https://www.googleapis.com/oauth2/v3/token
security.oauth2.client.userAuthorizationUri=https://accounts.google.com/o/oauth2/auth
security.oauth2.client.scope=profile email
security.oauth2.client.tokenName=oauth_token
security.oauth2.client.authenticationScheme=query
security.oauth2.client.clientAuthenticationScheme=form
security.oauth2.resource.userInfoUri=https://www.googleapis.com/userinfo/v2/me
security.oauth2.resource.preferTokenInfo=false
No i wszystko fajnie, odpalam SpringBoota, wklepuje localhost:8080/google/login gdzie powinienem dostać strone do logowania przez Google i ...
400. That’s an error.
Error: redirect_uri_mismatch
The redirect URI in the request, http://localhost:8080/login, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/211740207649-0ko4emc0t90q7mbn146jj3lusar4dlvj.apps.googleusercontent.com?project=211740207649
Doczytałem na SO i Githubie, że należy skonfigurować jeszcze autoryzowane identyfikatory URI, no to dodałem chyba wszystko co możliwe:
http://localhost:8080/google/login
http://localhost:8080/
https://localhost:8080/
https://localhost:8080/google/login
http://localhost:8080/google/login/
https://localhost:8080/google/login/
http://localhost:8080
http://localhost:8080/after
http://localhost:8080/after/
http://localhost:8080/login
(doczytałem gdzieś, że lepiej jest dodawać http i https)
Mógłby ktoś wytłumaczyć dlaczego nadal dostaję ten sam błąd Error: redirect_uri_mismatch i pokazać jaki powinny być prawidłowe identyfikatory URI wpisane do developer google?
dziękuje za wszystkie głosy pomocy :)
ps. wczesniej miałem ten sam problem przy odpalaniu autoryzacji oauth przy spotify