A KeycloakProtocolMapper defines how user attributes, roles, and other data are mapped into tokens. Protocol mappers can be attached to either clients or client scopes.
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakProtocolMapper
metadata:
name: my-mapper
spec:
# One of clientRef or clientScopeRef must be specified
clientRef:
name: my-client
# Or for client scopes:
# clientScopeRef:
# name: my-scope
# Required: Mapper definition
definition:
name: department
protocol: openid-connect
protocolMapper: oidc-usermodel-attribute-mapper
config:
user.attribute: department
claim.name: department
status:
ready: true
mapperID: "12345678-1234-1234-1234-123456789abc"
message: "Protocol mapper synchronized successfully"
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakProtocolMapper
metadata:
name: department-mapper
namespace: keycloak
spec:
clientRef:
name: my-client
definition:
name: department
protocol: openid-connect
protocolMapper: oidc-usermodel-attribute-mapper
config:
user.attribute: department
claim.name: department
jsonType.label: String
id.token.claim: "true"
access.token.claim: "true"
userinfo.token.claim: "true"
apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakProtocolMapper
metadata:
name: groups-mapper
namespace: keycloak
spec:
clientScopeRef:
name: my-scope
definition:
name: groups
protocol: openid-connect
protocolMapper: oidc-group-membership-mapper
config:
full.path: "false"
id.token.claim: "true"
access.token.claim: "true"
claim.name: groups
userinfo.token.claim: "true"
A KeycloakProtocolMapper belongs to either a client or client scope:
Reference Use Case
clientRefMapper applies to a specific client only
clientScopeRefMapper applies to all clients using the scope
Note: Exactly one of these must be specified.
The definition field accepts any valid Keycloak ProtocolMapperRepresentation :
Field Type Description
namestring Mapper name (required)
protocolstring Protocol (usually “openid-connect” or “saml”)
protocolMapperstring Mapper type (see common types below)
configobject Mapper-specific configuration
Mapper Type Description
oidc-usermodel-attribute-mapperMaps user attribute to token claim
oidc-usermodel-property-mapperMaps user property to token claim
oidc-group-membership-mapperIncludes group membership in token
oidc-role-name-mapperMaps role names
oidc-hardcoded-claim-mapperAdds hardcoded claim
oidc-audience-mapperAdds audience to token
oidc-full-name-mapperMaps full name
Mapper Type Description
saml-user-attribute-mapperMaps user attribute
saml-group-membership-mapperMaps group membership
saml-role-list-mapperMaps roles
Alias Full Name
kcpmkeycloakprotocolmappers
kubectl get kcpm
Mapper names must be unique within the client or client scope
The config values are all strings (including boolean values like “true”/“false”)
Changes to mappers affect all tokens issued after the change