Hello everyone,
I’m currently working on configuring token exchange in Keycloak and I’m running into an issue I haven’t been able to resolve.
I’ve tested with versions 26.2.5, and despite multiple configuration attempts the exchange keeps failing when using an Azure AD v2.0 access_token as the subject_token.
Could you please help me understand what I might be missing, or confirm if this is a limitation/bug in the current Keycloak version? Any guidance or examples from those who have successfully integrated Azure AD access tokens with Keycloak token exchange would be greatly appreciated
Tested Keycloak versions: 26.2.5
Scenario
- Trying to configure token-exchange between Keycloak and an external OIDC IdP (Azure AD).
- Azure AD issues a v2.0 access_token (validated independently against the Azure JWKS using OpenSSL – signature and
kidare correct). - Keycloak client
token-exchange-testhas Client authentication enabled, Authorization enabled, Standard Token Exchange enabled. - Token exchange request example:
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token_type=urn:ietf:params:oauth:token-type:access_token
requested_token_type=urn:ietf:params:oauth:token-type:access_token
audience=token-exchange-test
subject_token=<Azure access_token v2.0>
Expected behavior
Keycloak should accept the Azure AD access_token as subject_token and return a local access_token for the configured client.
Actual behavior
The request always fails with:
{
"error": "invalid_request",
"error_description": "Invalid token"
}
Keycloak logs (DEBUG/TRACE)
Failed to verify identity token: Key not found
Context about this error
- Even when Validate Signatures is disabled in the IdP config or pods are restarted, the error persists.
- The Azure token’s
kidexists in the tenant’s JWKS and signature validation succeeds outside Keycloak. - From the log, it seems Keycloak tries to validate the
subject_tokenas an ID Token issued by the local realm rather than an external access_token, which leads to the “Key not found” error.
Questions
- In Keycloak 26.2.5, is it required to configure a Client Policy with External Token Exchange to allow access_tokens from external IdPs?
- Has the validation logic for
subject_tokenchanged recently (i.e., does Keycloak only support ID Tokens by default)? - What is the supported way to enable token exchange using an external Azure AD access_token in 26.x?
