Skip to content

Instantly share code, notes, and snippets.

@radutoev
Created August 29, 2017 10:34
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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