Register custom OIDC scopes order-independently#4
Merged
Conversation
Snapshotting the scope registry into Passport::tokensCan() ran during the package boot, so a host app could only add custom scopes by racing provider boot order. Defer the snapshot to app booted() and add Identity::registerScope() so scopes registered from any provider reach Passport, discovery, and claim filtering regardless of order.
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.
Why
Custom OIDC scopes could only be added by racing service-provider boot order. The package snapshots the scope registry into
Passport::tokensCan()during its ownpackageBooted(), so a scope a host app registered later never became requestable. Consumers had to reach into the container with anafterResolving(ScopeRegistrar::class, …)hook installed inregister()— a workaround every consumer would otherwise need.The
ClaimAggregatorandDefaultDiscoveryBuilderwere already correct (they read theScopeRegistrarlive at request time); only the Passport snapshot was order-sensitive.What
app->booted()so it runs after every provider has booted. Scopes registered from any provider, in any order, are now captured.Identity::registerScope(string $scope, array $claims)— a public API that buffers intoIdentity::$scopesand is flushed into theScopeRegistrarduring boot. Safe to call fromregister()orboot().applyCustomScopes()) runs unconditionally; only thePassport::tokensCan()snapshot stays gated byregister_openid_scope, so apps managing Passport scopes themselves still get custom scopes into discovery and claim filtering.Tests
CustomScopeRegistrationTestloads a fixture provider afterlaravel-identityand asserts the scope lands inPassport::scopes(), the discovery document (scopes_supported+claims_supported), andScopeRegistrar::claimsFor()— failing if boot-order coupling ever returns.Full suite: 72 passing. Lint (ecs/php-cs-fixer/rector/tlint) clean.
Docs
README updated to document
Identity::registerScope()and drop the oldapp->extend()scope-registration example.