title: How to get Keycloak token in Spring
body: <p>I have <code>Spring</code> application with <code>Angular</code> frontend, I secured the two sides with <code>Keycloak 11.0.2</code>, how can I get the token information when a request is sent from a frontend, for example I want to access the authenticated user information and attributes in <code>Spring</code> side, because I the returned request depends on the users attributes.</p>
  <p>Below is my configuration in spring :</p>
  <pre><code>keycloak.auth-server-url=http://localhost:8080/auth
  keycloak.realm=myapp
  keycloak.resource=myapp-api
  keycloak.ssl-required=external
  keycloak.bearer-only=true
  keycloak.principal-attribute=preferred_username
  
  
  @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(jsr250Enabled = true)
  public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
      
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          super.configure(http);
          http.authorizeRequests().anyRequest().permitAll();
          http.csrf().disable();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
          keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
          auth.authenticationProvider(keycloakAuthenticationProvider);
      }
  
      @Bean
      @Override
      protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
          return new NullAuthenticatedSessionStrategy();
      }
  
      @Bean
      public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
          return new KeycloakSpringBootConfigResolver();
      }
  }
  </code></pre>