'Can not configure Keycloak 17 in spring boot app - still got unauthorized when i use bearer token authorization with access token
I want to get authorization with bearer token , i generate my access token using credentials from keycloak ,the problem is when i use this access token in the authorization with bearer i got always unauthorized. and when i use basic auth with credentials (username and password) i can access to the ressources wanted,still have this problem why i cannot access with bearer token
this my configuration
keycloak.realm = SpringBootKeycloak
keycloak.auth-server-url = http://127.0.0.1:8080
keycloak.ssl-required = external
keycloak.resource =springboot-microservice
keycloak.enable-basic-auth =true
keycloak.credentials.secret =2bbkqjIYxtB2TOdiXSfO0mJYwXoFoLN7
keycloak.bearer-only=true
keycloak-public-key=0OaMHHI4BR0bZAEr0zK7rByP8ckYKVOItjh8sGQzd7AkSbZhXARF02gpgCHuqZHO14EhycaAazC5GoOnea7ZFpQTs6mNu11mCnCiFBrpkh9MPUhIyUAdg0ohm8j39xdE0TTydLFeJLBs7E6vH1MPFqTyut7DnIuVXFu7Qwi3tDoDdNOBhdNAU9Q3z-CXxTdlVgEv8ICpt-UsfKIt7bgNtpPKdO_ozq_tZcosXCZ-ZS7AFbav2O0WM00tlBhmjq2hZXqzI55msOkzu9T1lp9cQRGcCZF5T9yhHWP_n1LmOaB-M-n3TAHGWFki9T83ecVVi2L5HRPNRRBPbKh23xjiWQ
@KeycloakConfiguration
@EnableWebSecurity
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter{
/**
* Registers the KeycloakAuthenticationProvider with the authentication manager.
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(keycloakAuthenticationProvider());
}
/**
* Defines the session authentication strategy.
*/
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(buildSessionRegistry());
}
@Bean
protected SessionRegistry buildSessionRegistry() {
return new SessionRegistryImpl();
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
super.configure(http);
http
.authorizeRequests()
// .anyRequest().authenticated();
.antMatchers("/MSJournalisation/**").hasAuthority("user");
// .anyRequest().authenticated();
}
}
for keycloak i use the latest version 17
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
