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:
- open admin console of realm.
- go clients , select client
- this works settings > access type confidential or public (not bearer-only)
- go mappers
- create mapping attribute json
- 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
Post a Comment