javascript - Include user locale to the Keycloak ID token -


i keycloak (1.4.0) include users' chosen locale id token.

i have come far creating user attribute mapper, supposed map locale attribute token, not work.

does know how this?

thanks in advance.

edit: have learnt know abput keycloak locales class: http://grepcode.com/file/repository.jboss.org/nexus/content/repositories/releases/org.keycloak/keycloak-forms-common-freemarker/1.2.0.final/org/keycloak/freemarker/localehelper.java#localehelper.0logger

i suppose have this:

  1. open admin console of realm.
  2. go clients , select client
  3. this works settings > access type confidential or public (not bearer-only)
  4. go mappers
  5. create mapping attribute json
  6. check "add id token"

to access mapped claim use this:

final principal userprincipal = httprequest.getuserprincipal();  if (userprincipal instanceof keycloakprincipal) {      keycloakprincipal<keycloaksecuritycontext> kp = (keycloakprincipal<keycloaksecuritycontext>) userprincipal;     idtoken token = kp.getkeycloaksecuritycontext().getidtoken();      map<string, object> otherclaims = token.getotherclaims();      if (otherclaims.containskey("your_claim_key")) {         yourclaim = string.valueof(otherclaims.get("your_claim_key"));     } } else {     throw new runtimeexception(...); } 

hope helps , fits use case. used custom attribute added custom theme.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -