keycloak client protocol mapper (script mapper) to add request header into token

折月煮酒 提交于 2019-12-08 05:06:26

问题


When I'm requesting a token from keycloak I want a specific header value (or extra form data) that was supplied in the request to be put in the JWT payload of the generated token. I've tried using a Script Mapper to get access to header values but I can't see how to get access to header values or data in the form data sent in any of the available script variables: user, realm, userSession, keyclockSession.


回答1:


You can get access to request headers using keycloakSession object, something like

keycloakSession.getContext().getRequestHeaders().getRequestHeader("User-Agent")

If you check the code for DefaultEvaluationContext class, that is how they add the User-Agent header.



来源:https://stackoverflow.com/questions/47233720/keycloak-client-protocol-mapper-script-mapper-to-add-request-header-into-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!