Repository navigation
providers/oauth2: token exchange - #23900
Merged
BeryJu merged 8 commits intoJul 10, 2026
Merged
Conversation
Add the RFC 8693 grant type identifier, the token type identifiers for access tokens and JWTs, and the invalid_target error code. The grant is added to the available choices only; existing providers are not opted in. Signed-off-by: Aubin Morand <[email protected]>
Add the token exchange grant to the token endpoint, implementing the impersonation case: a subject token issued by a federated provider or source is traded for an access token that speaks for the same user. Subject tokens are verified through the existing JWT federation trust, so a provider may only exchange tokens it already trusts for machine-to-machine authentication. Confidential clients must authenticate; the subject token is not a substitute for client credentials. Delegation is out of scope, so an actor token is refused rather than ignored. Token targeting is likewise unimplemented, so audience and resource are refused with invalid_target as required by RFC 8693 section 2.2.2. Both would otherwise leave a client believing a restriction had been applied when it had not. Signed-off-by: Aubin Morand <[email protected]>
Cover the impersonation path, the rejection of delegation and token targeting, unsupported token types, untrusted and unverifiable subject tokens, and the client authentication requirement. Signed-off-by: Aubin Morand <[email protected]>
Describe the trust configuration the grant relies on, the supported token type identifiers, and the parameters authentik refuses rather than silently ignores. Signed-off-by: Aubin Morand <[email protected]>
Signed-off-by: Aubin Morand <[email protected]>
Add the grant to the selectable list. It is deliberately absent from the default grant types, so the grant stays opt-in for new providers. Signed-off-by: Aubin Morand <[email protected]>
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Signed-off-by: Jens Langhammer <[email protected]>
BeryJu
approved these changes
Jul 10, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23900 +/- ##
==========================================
- Coverage 93.23% 93.20% -0.03%
==========================================
Files 1043 1044 +1
Lines 60990 61174 +184
Branches 424 424
==========================================
+ Hits 56862 57019 +157
- Misses 4128 4155 +27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
1 task
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.
Details
What does this PR change?
Adds RFC 8693 token exchange (urn:ietf:params:oauth:grant-type:token-exchange) to the OAuth2 provider, implementing impersonation: a client trades a subject token it already holds for an access token issued by another authentik provider, carrying the same user's identity.
Some parameters are refused rather than silently ignored, so a client is never misled about a restriction:
Why is this change needed?
Token exchange is the standard way for service A to call service B on behalf of the user who called A, without forwarding a token B was never issued for. authentik already has the primitives (federated provider trust, JWT access tokens, scope mappings, policies), so this is mostly wiring.
How was this tested?
New test_token_exchange.py (one file per grant, following the existing convention): success path, rejection of actor_token/audience/resource, unsupported token types, bad/expired/untrusted subject tokens, and the client-auth requirement. Full providers/oauth2 suite passes (15 new tests, no regressions); mypy --strict, bandit, and the web build/typecheck are clean.
Linked issues
Note: delegation is out of scope
This does impersonation only. Delegation (actor_token + the act claim) is a clean follow-up — actor_token is optional in the spec and act is additive, so nothing here blocks it. The open question is what authorizes an actor to act for a subject (honor may_act, an explicit allowlist, or a policy). Happy to take direction before building it.
Three deliberate choices, flagging for review
Checklist