Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use previously declared passport scopes and merge with OIDC scopes #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonerickson
Copy link

Currently PassportServiceProvider overwrites the scopes Passport recognizes with only the OIDC scopes provided in the config file:

Passport\Passport::tokensCan(config('openid.passport.tokens_can'));

This PR takes into account scopes that may have already been defined to be used by Passport and merges them with the OIDC scopes. It uses the Collection helper merge where the OIDC scopes will take precedence in the case of duplicates.

$openIdScopes = collect(config('openid.passport.tokens_can'));
$previousScopes = collect(Passport\Passport::scopes())->mapWithKeys(function (Passport\Scope $scope) {
    return [$scope->id => $scope->description];
});
Passport\Passport::tokensCan($previousScopes->merge($openIdScopes)->toArray());

If no scopes were previously defined, no behavior changes.

@ronvanderheijden
Copy link
Owner

I would recommend to publish the PassportServiceProvider instead.

@jonerickson
Copy link
Author

Do you mean just extending src/Laravel/PassportServiceProvider.php? In this case I would have to make sure and keep the boot method up-to-date with each update of your package. Seems like more work and more failure points to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants