feat(auth): KEYCLOAK_ALLOWED_AZP — let additional realm clients call the API - #317
Merged
telivity-otaip merged 2 commits intoAug 13, 2026
Merged
Conversation
…the API Both verifiers (the passport strategy and the WebSocket mirror) required azp === KEYCLOAK_CLIENT_ID. azp is immutably the client that obtained the token, so a service account on its own realm client can never pass a single-value equality, no matter what audience mappers it carries — an integration authenticating with client credentials gets 401 "Invalid token audience (azp mismatch)" with no way through except impersonating the browser client. KEYCLOAK_ALLOWED_AZP is a comma-separated list of realm clients allowed to call. Unset, behaviour is byte-for-byte the old one — only the primary client passes — so existing deployments notice nothing. aud stays single-valued and separately validated: the list widens WHO may call, not what audience a token must carry. Both verifiers read the same list, or a caller would work over HTTP and die on the socket. Tests pin all four properties: unset = old behaviour, listed clients pass, unlisted still fail, tokens without azp unaffected.
Co-authored-by: telivity-otaip <telivity-otaip@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Both token verifiers (the passport HTTP strategy and the WebSocket mirror) require
azp === KEYCLOAK_CLIENT_ID.azpis immutably the client that obtained the token — no audience mapper changes it — so a service account authenticating with client credentials on its own realm client can never pass. An integration gets401 Invalid token audience (azp mismatch)with no way through except sharing the browser client, which is a public client that can't hold a secret.We hit this integrating a companion service (enquiry pipeline) against the API: audience mapper added,
audcorrect, still 401 — measured live before we understood the guard.The change
KEYCLOAK_ALLOWED_AZP: a comma-separated list of realm clients allowed to call.audstays single-valued and separately validated: the list widens who may call, not what audience a token must carry (callers still add the audience via a mapper).Tests
All four properties pinned: unset = old behaviour; listed clients pass; unlisted clients still fail; tokens without
azpare unaffected (unchanged semantics).