I’m using Keycloak’s Java keycloak-admin-client
and I’m wanting to set up some protocol mappers for my realm’s client.
The Java API exposes this class to create a protocol mapper and then the following method to set the config options:
ProtocolMapperRepresentation protocolMapperRep = new ProtocolMapperRepresentation();
protocolMapperRep.setConfig(Map.of("some.mapper.config.option", "mapper-value"));
I saw a few options from another StackOverflow question here: Add protocol-mapper to keycloak using kcadm.sh
However, there has to be a better place where these are documented.
IMHO there is no documentation. I use Keycloak console (UI) and browser network console to get idea about parameters, config options and their values.
That’s what I was worried about. So if I understand correctly, you use the developer mode and create a new mapper in the browser (localhost) and inspect the request that gets sent?
Long story short, yes. Doing what Jangaraj described above worked for me. I got similar advice on Stack Overflow.
I ended up doing something like this for a user attribute mapper:
ProtocolMapperRepresentation protocolMapper = new ProtocolMapperRepresentation();
protocolMapper.setProtocol("openid-connect");
protocolMapper.setProtocolMapper("oidc-usermodel-property-mapper");
protocolMapper.setName(claim);
protocolMapper.setConfig(
new HashMap<>() {
{
put("jsonType.label", type);
put("access.token.claim", "true");
put("id.token.claim", "true");
put("userinfo.token.claim", "true");
put("user.attribute", claim);
put("claim.name", claim);
}
});
It’s a real shame that there isn’t any proper documentation on this.
Following up year 2022 still the same