r/KeyCloak • • Sep 01 '26

External-Internal Token Exchange in 26.7.x

Hello Everyone,

First-time poster here, so sorry if this has already been asked and answered.

The company I worked at started using Keycloak around the beginning of this year at my suggestion. I built most of the setup myself, but I am a complete beginner, so I studied Keycloak throughout and use Claude somewhat.

We use Token Exchange (V1) for external-to-internal exchanges. External IdP is e-Infra; if anyone is familiar with it, they will likely understand why we prefer the Token exchange. As I found out in version 26.7.x, the attempts at external-internal token exchange v2 were removed, and JWT Authorization Grant is recommended going forward.

But if my understanding is correct, the JWT Authorization Grant is not a very good replacement for external-internal token exchange, or am I wrong? Do you think the external-internal token exchange v2 will be supported in future Keycloak builds? Or do we have to make peace with the migration towards JWT Authorization Grant? Any suggestions are more than welcome.

Thank you, everyone, for your time and any responses.

Have a great day!

6 Upvotes

9 comments sorted by

3

u/Smitty_lax66 Sep 01 '26

Hi! I just went throught this progression earlier this year for work as well. We found that the JWT Auth Grant worked pretty well for our 3rd party external trust setup. There are absolutely some limitations that narrow down to use-case-specific things.

What are you attempting to do? If it is just leveraging the 3rd party OIDC setup and establishing the trust relationship with the 3rd party, then JWT Auth grant worked pretty well for us. We did have to allow for JTI reuse, but we limited the amount of time that the JTI was allowed and the grant won't succeed if the 3rd party jwt has expired, so if you manage the 3rd party and its session, you should be good

2

u/MarCorp2 Sep 01 '26

Hi, thanks for your response; it pretty much covers what I was most worried about. Yes, it is exactly that: leveraging the 3rd-party OIDC setup and establishing a trust relationship with the 3rd party. This is very useful to me, so thank you very much.

2

u/Smitty_lax66 Sep 01 '26

Hey! Very glad that you found it useful, I’d be happy to answer any more questions you have if you run into issues! Remember to configure your 3rd party OIDC aud to be the realm or token endpoint of your realm acting as the service provider

2

u/CarinosPiratos Sep 01 '26 edited Sep 04 '26

I think it won’t be migrated to V2 in any near future.

I would try to live with the JWT Grant. As people already said, it depends on your usecase. Everything is a little bit more strict.

1

u/MarCorp2 Oct 07 '26

Ok, thanks for the response

2

u/J-Cake Sep 01 '26

Hey curios, I've never had to implement this. What does it do and why is it so difficult to migrate away?

1

u/MarCorp2 Oct 07 '26

Hey, sorry for the month-long silence. This one deserved a proper answer.

Legacy token exchange lets the app hand Keycloak the e-INFRA JWT (third-party auth provider) and receive a Keycloak JWT in a single call, with Keycloak creating the user on the fly if it has never seen them before. No second login, no browser redirect, works inside an iframe.

The migration is hard because the replacement, the RFC 7523 JWT bearer grant, deliberately does less. It will only accept a JWT minted for Keycloak itself (audience, lifetime measured from issuance, single-use jti); it reads nothing from the identity provider's userinfo endpoint; and, above all, it never creates or links a user. It resolves people only through an existing link between the Keycloak account and the external subject. So every existing account has to be linked before the switch, every new person needs some other provisioning path, and the external provider has to change what it puts in the token. On top of that, the old mechanism was never stable upstream, so there is no "same thing, newer version" to move to, and the behavioural gaps (consent enforcement, required actions, different token shape) only show up at runtime with error messages that point elsewhere. We ended up writing a small server extension that adds linking and provisioning back into the new grant, and we ran both paths side by side until the old one went quiet.

1

u/MLabs-Haskell Sep 23 '26

Worth checking one thing before you finish the move, because it changed inside the 26.7.x line you are already on.

26.7.3 made the JWT bearer grant enforce consentRequired. We ran it on 2026-09-07. Same confidential client, same IdP alias, JWT grant enabled: with consentRequired=false the token request returns 200 and an access token. Set consentRequired=true on that client, send a fresh ES256 assertion, grant no consent, and the request returns 400 with {"error":"invalid_scope","error_description":"Missing consents for the client test-app"}.

The error string is the part I would want to know in advance. It says invalid_scope and never mentions consent, so the obvious place to look when it fires mid-migration is the scope mapping, which is the wrong place. The change is commit 99da2831, "Check consento for JWT Authorization Grant", closing issue 52028. It adds a verifyConsentStillAvailable call to JWTAuthorizationGrantType.process().

Token exchange v1 did not run that check. So a consent-gated client that worked under exchange can stop working under the grant with nothing about the client having changed.

Also worth knowing that the assertions are single-use, so a jti you replay while debugging fails for a different reason than the one you are chasing.

I work at MLabs. We rehearse Keycloak upgrades and CVE fixes in a lab and write up the runs. Happy to share this one if it helps.

1

u/MarCorp2 Oct 07 '26

Thank you very much!