feat(auth0-server-js): Support scope mapping and base scopes#125
Open
jacobovidal wants to merge 15 commits into
Open
feat(auth0-server-js): Support scope mapping and base scopes#125jacobovidal wants to merge 15 commits into
jacobovidal wants to merge 15 commits into
Conversation
…ate options vs methods
…ent in login flows
Comment on lines
+159
to
+165
| const targetAudience = requestedAudience || configuredAudience || DEFAULT_AUDIENCE; | ||
|
|
||
| // Get base scope for the target audience | ||
| const baseScope = getScopeForAudience(configuredScope, targetAudience); | ||
|
|
||
| // Merge base scope with requested scope | ||
| const resolvedScope = mergeScopes(baseScope, requestedScope); |
Member
There was a problem hiding this comment.
Would it make sense to call resolveTokenScopes here to make it clear it;s doing the same, and additionally ensures it has openid.
Suggested change
| const targetAudience = requestedAudience || configuredAudience || DEFAULT_AUDIENCE; | |
| // Get base scope for the target audience | |
| const baseScope = getScopeForAudience(configuredScope, targetAudience); | |
| // Merge base scope with requested scope | |
| const resolvedScope = mergeScopes(baseScope, requestedScope); | |
| const resolvedScope = resolveTokenScopes(configuredScope, configuredAudience, requestedAudience, requestedScope); |
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
This adds support for per-audience scope configuration in
auth0-server-js, enabling flexible scope management for Multi-Resource Refresh Tokens (MRRT). Applications can now configure different base scopes for different APIs using a Record mapping.Warning
PR Dependency
DO NOT MERGE until PR #124 is merged.
Changes in
auth0-server-jsPer-audience scope configuration
The
scopeparameter inauthorizationParamsnow supports both string and Record formats, allowing different base scopes for different audiences:Scope handling behavior
At initialization, the
ServerClientconstructor normalizes the scope configuration to ensure consistent behavior. The scope handling follows these rules:When NO scope is provided
Default scopes (
email offline_access openid profile) are automatically set:When a STRING scope is provided
The scope is preserved as-is without adding defaults (respects explicit configuration):
When a RECORD scope is provided
Each audience's scope is preserved as-is. Defaults are only added for the configured audience if not explicitly specified:
If the configured audience is not present in the Record, defaults are added:
Note
This behavior matches
nextjs-auth0: explicit scope configuration is respected, and defaults are only injected when nothing is specified.Note
Although
auth0-auth-jsinjects default scopes, we addedauth0-server-jsspecific server-side defaults. This is intentional, asauth0-spa-jswill eventually be based onauth0-auth-js, and server-side applications require different default scopes than client-side SPAs.Scope resolution and merging
At request time, scopes are automatically merged, deduplicated, and sorted when combining base configuration with method-level options:
Important
For login operations (
startInteractiveLogin,loginBackchannel), theopenidscope is always guaranteed to be present, even if not explicitly requested. This ensures ID tokens are always returned.Scope behavior summary
{}'email offline_access openid profile'scope: 'read:data''read:data'(as-is)scope: {'api': 'read:api'}+audience: 'api''read:api'(as-is)scope: {'api1': 'x'}+audience: 'api2'{'api1': 'x', 'api2': 'email offline_access openid profile'}'read:data'+ Requested:'write:data''read:data write:data'(merged){'api': 'read:api'}+ Requested:'write:api'forapi'read:api write:api'(merged)