Skip to content

Skip disabled identity providers when looking up a token exchange subject issuer - #53756

Open
ybai08 wants to merge 1 commit into
keycloak:mainfrom
ybai08:fix/token-exchange-skip-disabled-idp
Open

ybai08 wants to merge 1 commit into
keycloak:mainfrom
ybai08:fix/token-exchange-skip-disabled-idp

Conversation

@ybai08

@ybai08 ybai08 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Closes #49205

In an external-to-internal token exchange, subject_issuer can be an identity provider alias or the issuer of the token. When it is not an alias, AbstractTokenExchangeProvider.locateExchangeExternalTokenByAlias asks every provider that can exchange external tokens whether it is the issuer. It builds each provider with IdentityBrokerService.getIdentityProvider, which throws IdentityBrokerException for a disabled provider, and nothing in that loop catches it. Providers come back ordered by alias, so a disabled provider whose alias sorts ahead of the matching one makes the exchange fail with a 500.

The lookup now queries only enabled providers, with the same IdentityProviderQuery...with(IdentityProviderModel.ENABLED, "true") that LinkedAccountsResource and AccountConsole use.

Test

KcOidcBrokerTokenExchangeTest gets testExternalInternalTokenExchangeUsingIssuerWithDisabledProvider: a disabled OIDC provider with the alias a-disabled-idp ahead of the broker, and an exchange by issuer.

While writing it I found that the existing testExternalInternalTokenExchangeUsingIssuer never took this path: assertExternalToInternalExchange ignored its subjectIssuer argument and the request always sent the alias. The helper now sends the issuer it is given. The other callers keep sending the alias.

What I ran

  • ./mvnw test -Pauth-server-quarkus -Dtest=KcOidcBrokerTokenExchangeTest -pl testsuite/integration-arquillian/tests/base
    • on main with only the test change: 11 run, 1 failure, the new test (Expected: <200> but: was <500>). The other 10 pass, including the issuer test that now really sends the issuer.
    • with the fix: 11 run, 0 failures.
  • ./mvnw spotless:check -pl services,testsuite/integration-arquillian/tests/base: clean.
  • Not run: the rest of the base testsuite, and token exchange V2 tests (they do not use this lookup with a disabled provider).

AI usage: an AI agent was used to write this change; I have reviewed it.

…ject issuer

When subject_issuer is not a provider alias, the external-to-internal
exchange looks for a provider that claims the issuer among all providers
that can exchange external tokens. A disabled one made the lookup throw, so
the exchange failed with a 500 whenever such a provider sorted ahead of the
one that matches. Query only enabled providers.

The issuer test now sends the issuer it is given; it sent the alias before.

Closes keycloak#49205

Signed-off-by: Yang Bai <271969568+ybai08@users.noreply.github.com>
@ybai08
ybai08 requested review from a team as code owners October 8, 2026 16:26
Copilot AI balanced review requested due to automatic review settings October 8, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ybai08

ybai08 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

The one red job, FIPS IT (non-strict), failed in X509BrowserLoginTest.loginWithRevalidateCertEnabledCertIsTrustedAndCASubjectDN with Server did not become ready within 120 seconds: https://localhost:8443/realms/master (198 run, 0 failures, 1 error). That test does not use token exchange, and this change touches only AbstractTokenExchangeProvider and KcOidcBrokerTokenExchangeTest. I cannot re-run the job from a fork; could someone with access re-run it?

@ybai08

ybai08 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@mposolda, could you take a look at this when you have time? It fixes #49205: a token exchange fails when another identity provider in the realm is disabled. It's a one-line change in AbstractTokenExchangeProvider plus a test in KcOidcBrokerTokenExchangeTest. The one red CI job is the unrelated FIPS timeout described above.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token Exchange fails if another provider is disabled

2 participants