[keycloak-user] Getting the user id from the access token
Juan Diego
juandiego83 at gmail.com
Fri Jul 10 19:01:07 EDT 2015
Where do you get sessionContext from?
On Fri, Jul 10, 2015 at 5:54 PM, Scott Dunbar <scott at xigole.com> wrote:
> I use something like:
>
> import org.keycloak.KeycloakPrincipal;
> import org.keycloak.KeycloakSecurityContext;
> import org.keycloak.representations.IDToken;
>
> ...
>
> @Resource
> private SessionContext sessionContext;
>
> ...
>
> @SuppressWarnings("unchecked")
> KeycloakPrincipal<KeycloakSecurityContext> kcPrincipal = (KeycloakPrincipal<KeycloakSecurityContext>)(sessionContext.getCallerPrincipal());
> IDToken idToken = kcPrincipal.getKeycloakSecurityContext().getIdToken();
>
> log.debug( "email from token is \"" + idToken.getEmail() + "\"" );
>
>
> Not sure if that's the recommended way but it works well.
>
>
> On 07/10/2015 04:48 PM, Juan Diego wrote:
>
> Hi
>
> I want to be able to update the user password and some preferences from
> my web app, in order to update some of the user info from my portal i can
> see in the rest api that you need the user ID.
> I have a backend with java that should connect to my keycloak server once
> it gets the token
>
> KeycloakSecurityContext securityContext = (KeycloakSecurityContext)
> httpRequest
> .getAttribute(KeycloakSecurityContext.class.getName());
>
> AccessToken accessToken = securityContext.getToken();
>
> I dont know how to get info from the accesToken, or does the access token
> class already has methods to do that. I know this is more of a question of
> design. This part is not really clear for me.
>
> Thanks
>
>
>
> _______________________________________________
> keycloak-user mailing listkeycloak-user at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/keycloak-user
>
>
> --
> Scott Dunbar
> Xigole Systems, Inc.
> Enterprise consulting, development, and hosting
> 303·667·6343
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20150710/8ab143e1/attachment.html
More information about the keycloak-user
mailing list