feat: Adds Custom Token Exchange support#258
Merged
Merged
Conversation
nandan-bhat
reviewed
Jun 30, 2026
kailash-b
enabled auto-merge (squash)
June 30, 2026 09:45
nandan-bhat
approved these changes
Jun 30, 2026
Merged
This was referenced Jul 8, 2026
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.
By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.
Description
This PR adds support for Custom Token Exchange (RFC 8693) to the SDK, letting an application exchange an existing external/custom security token for Auth0 tokens without a browser redirect. The primary use cases are delegation/impersonation and agent-identity scenarios. It requires a configured Custom Token Exchange Profile and a validation Action in the Auth0 tenant.
The feature is exposed through a new
HttpContext.CustomTokenExchangeAsync(CustomTokenExchangeRequest)extension method:CustomTokenExchangeRequestdescribes the exchange:SubjectTokenandSubjectTokenType(required), plus optionalAudience,Scope,ActorToken/ActorTokenType(delegation pair), andOrganization.CustomTokenExchangeResultreturns the exchanged tokens (AccessToken,IdToken,RefreshToken,ExpiresIn,Scope) and the decodedact(actor) claim (Act) for delegation flows.CustomTokenExchangeExceptionis thrown on client-side validation failures or token-endpoint rejections, carryingStatusCode,Error, andErrorDescriptionfor the latter. It never carries token-bearing bytes.Stateless by design.
CustomTokenExchangeAsyncperforms the exchange and returns the tokens but has no session side-effects — it does not sign the user in or write any cookie. The caller decides what (if anything) to persist.Client-side validation (
CustomTokenExchangeRequestValidator) runs before any network call:subject_tokenmust be non-empty and must not include aBearerprefix;subject_token_typemust be a valid URI (URL or URN), 10–100 characters, and the reservedurn:ietf:andurn:auth0:namespaces are rejected; an actor token requires its matching type and vice-versa.Delegation / impersonation. When an actor token pair is supplied, the
actclaim from the returned ID token is decoded and exposed onresult.Act(ActClaimReader). The outermostSubis the current actor; nestedActvalues are prior actors and are informational only. Auth0 suppresses the refresh token in delegation flows.The exchange is implemented on
TokenClient(ExchangeCustomToken) and integrates with the SDK's existing domain resolution (including Multiple Custom Domain support) and backchannel client.References
Testing
Unit/integration tests were added covering the new functionality:
Checklist
main