Skip to content

Keycloak init script update : support audience (oidc-audience-mapper) protocol mappers #2667

Closed

Description

@KashiwalHarsh

create_mapper in keycloak-init/keycloak_init.py hardcodes
protocolMapper: "oidc-usermodel-attribute-mapper", so it can only create
user-attribute mappers. There's no way to configure an audience mapper, so
realm clients get only Keycloak's default aud (e.g. ["account"]).

Request: let a mapper entry specify its type and, for oidc-audience-mapper,
set included.client.audience / included.custom.audience with
access.token.claim=true, driven from the realm YAML config.

Acceptance criteria:

  • A mapper entry can declare its type (default stays oidc-usermodel-attribute-mapper).
  • oidc-audience-mapper entries support included_client_audience or
    included_custom_audience and emit the value into the access token's aud.

Activity

  1. self-assigned this
    on Oct 14, 2026
  2. added a commit that references this issue on Oct 21, 2026
    be56a7e
  3. Ivanmeneges commented on Oct 23, 2026

    @Ivanmeneges
    Contributor

    The Keycloak init script now supports audience mappers. The change is merged in mosip/keycloak release-1.3.x through mosip/keycloak#216 (be56a7e).

    keycloak-init/keycloak_init.py no longer hardcodes oidc-usermodel-attribute-mapper. Each client mappers entry is passed to mapper_payload:

    • Leave protocol_mapper unset, or set oidc-usermodel-attribute-mapper, to keep the existing user-attribute mapper (mapper_name, mapper_user_attribute, token_claim_name).
    • Set protocol_mapper: oidc-audience-mapper and exactly one of included_client_audience or included_custom_audience. The script sets access.token.claim to true and adds that value to the access token aud.
    • An entry with both audience fields, or any other protocol_mapper, is rejected before a realm or client is created. A re-run skips a mapper name that already exists (HTTP 409). To change an audience, delete that mapper in Keycloak and run init again.

    Example:

    - name: mosip-pms-client
      mappers:
        - mapper_name: esignet-audience
          protocol_mapper: oidc-audience-mapper
          included_client_audience: mosip-ida-client

    Tested on a fresh Keycloak in the Nexus cluster with keycloak_init.py from release-1.3.x. Init created esignet-audience on mosip-pms-client as oidc-audience-mapper with included.client.audience=mosip-ida-client and access.token.claim=true. Running init again updated the realm and clients and skipped that mapper.

    The Helm chart image tag is still mosipid/keycloak-init:1.3.0. The merge published the new script as mosipid/keycloak-init:release-1.3.x. deploy/keycloak/keycloak-init.sh installs chart 12.0.2, which uses tag 1.3.0, so that job does not pick up this change until the image tag is updated. The audience entry in helm/keycloak-init/values.yaml is a comment; add it on the client that needs it.

  4. Ivanmeneges commented on Oct 26, 2026

    @Ivanmeneges
    Contributor

    After it was tested and worked fine raised the same changes to develop branch and below is the PR for the same
    PR: mosip/keycloak#217

  5. Ivanmeneges commented on Oct 27, 2026

    @Ivanmeneges
    Contributor

    The PR has been merged for the same so now the request has been in place in both develop and release-1.3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

End Date

None yet

Complexity

None yet

Start Date

None yet

Original Estimate

None yet

Time Tracking

None yet

Resolved By

Ivan

Story Points

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions