Hej, jak powinna wyglądać konfiguracja oauth2 client w spring boocie?
W tej chwili mam taki plik application.yml:
spring:
security:
oauth2:
client:
registration:
example:
client-id: ${EXAMPLE_CLIENT_ID}
client-secret: ${EXAMPLE_CLIENT_SECRET}
authorization-grant-type: authorization_code
redirect-uri: '{baseUrl}/login/oauth2/code/'
client-authentication-method: BASIC
scope:
- read
- write
provider:
example:
authorization-uri: 'example.com/oauth/authorize/'
token-uri: 'example.com/api/open/oauth/token'
user-info-uri: 'example.com/api/partner/users/me'
user-info-authentication-method: BASIC
userNameAttribute: id
I taką klasę konfiguracyjną:
@Configuration
class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/home", "/login**","/callback/", "/webjars/**", "/error**", "/oauth2/authorization/**").permitAll()
.anyRequest().authenticated().and()
.oauth2Login()
.successHandler(successHandler());
}
@Bean
SimpleUrlAuthenticationSuccessHandler successHandler(){
return new SimpleUrlAuthenticationSuccessHandler("/hello");
}
}
I tak:
- loguje się -> leci GET pod:
example.com/oauth/authorize/?response_type=code&client_id=id&scope=scope&state=state=&redirect_uri=moja-apka/login/oauth2/code/
- leci GET z odp 500:
moja-apka/login/oauth2/code/?code=code&state=state
Czyli tutaj to wygląda git - wysłało get pod prawidłowo wygenerowany url, z example.com dostałem odpowiedź z code i state ale i tak:
3. zostaje przekierowany na Whitelabel Error Page
W logach widzę tylko, że gdzieś tam po drodze wyrzuciło:
org.springframework.http.converter.HttpMessageNotReadableException: An error occurred reading the OAuth 2.0 Error: errorCode cannot be empty; nested exception is java.lang.IllegalArgumentException: errorCode cannot be empty