如何通过 REST API 为 Keycloak 中的每个用户属性创建映射器?

How to create mapper for each user attribute in Keycloak via REST API?

如何通过 Keycloak 的 REST API 创建具有以下值(如附图所示)的协议映射器?我无法在文档中找到它 - 我确实找到了这个:Protocol Mapper - but the ProtocolMapperRepresentation 接受一个 Map 和几个字符串。当我看到 UI - 我看到了更多的字段,但我不确定我是否在看正确的 API.

这是UI:

如何通过 API 完成?

How do I create Protocol Mappers with the following values (as seen in the attached image) via Keycloak's REST API?

您可以通过调用以下端点来完成:

POST ${KEYCLOAK_HOST}/auth/admin/realms/${REALM_NAME}/clients/${ID of the Client}/protocol-mappers/models

具有以下数据:

{"protocol":"openid-connect","config":{"id.token.claim":"true","access.token.claim":"true","userinfo.token.claim":"true","multivalued":"","aggregate.attrs":"","user.attribute":"some-attribute","claim.name":"some-attribute","jsonType.label":"String"},"name":"some-attribute","protocolMapper":"oidc-usermodel-attribute-mapper"}

I did find this: Protocol Mapper - but the ProtocolMapperRepresentation takes in a Map and a couple of Strings. When I see the UI - I see a lot more fields and I'm not sure if I'm looking at the right API.

这是设计使然;使端点足够抽象以接受不同类型的协议映射器。该 Map 基本上对配置部分进行编码,该部分往往会从映射器更改为映射器。