[keycloak-user] Recommended way to identify user from token

Conrad Winchester conrad at mindless.com
Tue Jun 10 01:16:24 EDT 2014


Hi,

I have keyclick integrated into my application and have it protecting several end points. A user can login to get access to the protected resources by adding the bearer token into the authorisation header.

I was wondering what the recommended way is to actually identify the user who has authenticated. Is this the way to do it?


 	@Context
  	private SecurityContext securityContext;
.
.
.
      KeycloakPrincipal principal = (KeycloakPrincipal)securityContext.getUserPrincipal();
      logger.info("Logged in user: "+ principal.getName());

I noticed the the name is the ‘id’ of the user from the keycloak table.

Are there any other ways to get data from the token?

Thanks

Conrad


More information about the keycloak-user mailing list