feat(auth0-express-api):add support for on-behalf-of token exchange - #40
Open
nandan-bhat wants to merge 3 commits into
Open
feat(auth0-express-api):add support for on-behalf-of token exchange#40nandan-bhat wants to merge 3 commits into
nandan-bhat wants to merge 3 commits into
Conversation
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.
What
auth0-express-apican now exchange the caller's access token for one issued to a downstream API, still representing the same user. This is On-Behalf-Of token exchange (RFC 8693).Why
Today an app that wants this has to add
@auth0/auth0-api-jsas a direct dependency, build its ownApiClient, and pull the raw token off the request itself. The token was not even available onreq.auth0, so there was nothing to exchange.Notes for reviewers
The exchanged token defaults to the verified one.You do not pass it in. That is why the route needsrequiresAuth(). An optionalsubjectTokencovers the case where the token comes from somewhere else, such as one held for a background job. Making the caller always supply a token would invite passing an unverified one.Startup validation is a behavior change.createAuth0Api()now throws whenclientIdis set withoutclientSecretorclientAssertionSigningKey, and when a credential is set without aclientId. An app that only verifies tokens but has a strayAUTH0_CLIENT_IDin a shared.envwill now fail to boot. Deliberate:clientIdalone can never work server side, and failing at startup beats failing on a real request in production.getTokenOnBehalfOfis optional onreq.auth0, so call sites need!. Making it required breaks theas Partial<Request>mock pattern that five spec files in this package rely on (TS2741). This is inconsistent withauth0-express, wherereq.auth0.clientis required. Worth settling for both packages, separately from this PR.Testing
New specs for
requiresAuth()(its first unit tests), for the exchange helper, and for the public export surface. The integration tests assert the exact token exchange request body sent to the tenant.