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

Marek Posolda mposolda at redhat.com
Fri Jun 13 09:37:03 EDT 2014


IDToken idToken = securityContext.getIdToken()

Then idToken has methods like "getName()", "getPreferredUsername()", "getEmail()" etc. You can use just those, which are mapped as allowed Claims for this client (You can configure claims in Keycloak admin console). Those, which are not mapped as claims will return null.

Marek


On 10.6.2014 07:16, Conrad Winchester wrote:
> 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
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user



More information about the keycloak-user mailing list