Skip to content

Instantly share code, notes, and snippets.

@radutoev
Created August 29, 2017 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save radutoev/7ad5c8bc1fa98188bebf9ab05bfea062 to your computer and use it in GitHub Desktop.
Save radutoev/7ad5c8bc1fa98188bebf9ab05bfea062 to your computer and use it in GitHub Desktop.
Keycloak access token bean
@Component
public class KeycloakUtils {
@Bean
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
proxyMode = ScopedProxyMode.TARGET_CLASS)
public AccessToken accessToken() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes())
.getRequest();
AccessToken accessToken = ((KeycloakPrincipal) ((KeycloakAuthenticationToken) request.getUserPrincipal()).getPrincipal())
.getKeycloakSecurityContext().getToken();
return accessToken;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment