问题
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