THREESCALE-15279: Add an "audience" protocol mapper to Keycloak integration#597
THREESCALE-15279: Add an "audience" protocol mapper to Keycloak integration#597jlledom wants to merge 2 commits into
Conversation
RHBK 26.6.2+ rejects token introspection when the calling client is not in the token's aud claim. Previously, Zync created OIDC clients without an audience mapper, so tokens only contained aud: "account". This caused introspection to fail with "Client '<client_id>' is not in the token audience". Add an oidc-audience-mapper protocol mapper to every client created or updated by Zync. The mapper injects the client's own ID into the aud claim of access tokens, satisfying RHBK's new validation requirement while leaving ID tokens unchanged. Assisted-by: Claude Code
The audience mapper feature added protocolMappers to the client payload sent to Keycloak. WebMock stubs in integration tests were matching on exact request bodies without this field, causing 5 test failures. Update all affected stubs to include the audience mapper in their expected request bodies. Assisted-by: Claude Code
Compatibility & Correctness ReviewThe code change itself is clean and correct for the target use case (RHBK 26.6.2+). The However, there are two operational risks worth discussing before merge: 1. "Allowed Protocol Mapper Types" policy will reject clients with 403By default, Keycloak's Client Registration Policies do not whitelist The PR description documents this as verification step 1, but it's actually a hard prerequisite — not a verification step. This should be surfaced prominently in release notes or a migration guide. Ideally, Zync would detect the 403 and log a clear message pointing at the policy configuration. 2. Potential overwrite of existing protocol mappersPreviously, Worth verifying this behavior against the target Keycloak version, or consider reading the existing client's mappers and merging. Test coverage gaps
SuggestionConsider making the mapper configurable via |
Jira Issue:
https://redhat.atlassian.net/browse/THREESCALE-15279
Description:
As the issue describes, after a breaking change in a recent RHBK release, the token introspection feature stopped working. In order to fix it, we need to ensure the access token received from keycloak includes the client id in the
audfield.Keycloak provides a way to write on this field, which is installing a protocol mapper type
oidc-audiende-mapperin all clients.This PR modifies the Keycloak integration in Zync to add such mapper in the requests to the client registration service in Keycloak.
Verification steps:
oidc-audience-mapperfor client registrationoidc-audience-mapperto theAllowed Protocol Mapper Typespolicy for bothAnonymousandAuthenticatedclients{"active": false}then it's not working.