keycloak客户端协议映射器(脚本映射器),用于将请求标头添加到令牌中 [英] keycloak client protocol mapper (script mapper) to add request header into token

查看:424
本文介绍了keycloak客户端协议映射器(脚本映射器),用于将请求标头添加到令牌中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从密钥斗篷请求令牌时,我希望将请求中提供的特定标头值(或额外的表单数据)放入生成的令牌的JWT有效负载中.我尝试使用脚本映射器访问标头值,但看不到如何在任何可用脚本变量(userrealmuserSessionkeyclockSession.

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.

推荐答案

您可以使用keycloakSession对象访问请求标头,例如

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

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

如果检查DefaultEvaluationContext类的代码,这就是它们添加User-Agent标头的方式.

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

这篇关于keycloak客户端协议映射器(脚本映射器),用于将请求标头添加到令牌中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆