feat(auth0-server-js): add loginWithCustomTokenExchange and customTokenExchange methods#176
Open
cschetan77 wants to merge 3 commits into
Open
feat(auth0-server-js): add loginWithCustomTokenExchange and customTokenExchange methods#176cschetan77 wants to merge 3 commits into
cschetan77 wants to merge 3 commits into
Conversation
bd5cc6f to
12cfbca
Compare
77b32f4 to
1ef94d5
Compare
ba61a9a to
97b20dc
Compare
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.
Description
Adds first-class Custom Token Exchange (CTE) support to ServerClient in auth0-server-js, building on the actor token and act claim foundation added to auth0-auth-js.
loginWithCustomTokenExchange(options, storeOptions?): exchanges a custom external token (e.g. a Google ID token, a legacy system token) for Auth0 tokens and persists the result as a user session in the StateStore. Equivalent to completing an interactive login flow, but without a browser redirect. Calls stateStore.set with removeIfExists: true to prevent session fixation. ReturnsPromise<LoginWithCustomTokenExchangeResult>, surfacing authorizationDetails from the token response for callers using RAR (authorization_details in extra).customTokenExchange(options, storeOptions?): performs the same RFC 8693 token exchange but returns the raw TokenResponse without touching the StateStore. Designed for delegation and impersonation flows where downstream tokens are needed but no session should be created or modified.LoginWithCustomTokenExchangeOptionsandCustomTokenExchangeOptionstype aliases in types.ts, both derived fromExchangeProfileOptionsinauth0-auth-js. This keeps the types consistent across the monorepo and inheritsactorToken,actorTokenType, and all other exchange options automatically. Also addedLoginWithCustomTokenExchangeResultinterface to types.tsBoth methods follow the same domain resolution and AuthClient routing pattern used by loginBackchannel, supporting both static domain and resolver mode configurations.
The return of
Promise<LoginWithCustomTokenExchangeResult>containingauthorizationDetailsis kept in consistent withcompleteInteractiveLoginandloginBackchannelmethods. Though the case for returning it is narrow.Testing
Unit tests
Checklist