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

[5.x] Adds support for configuring Access Scope for providers from configuration #728

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

TheAladeen
Copy link
Contributor

Hi All,

Description

This PR adds support for easily adding Access Scopes for 0Auth Providers by specifying the scopes key in the application's config/services.php as shown below:

    'github' => [
        'client_id'     => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect'      => env('GITHUB_REDIRECT_URI'),
        'scopes'        => ['read:user', 'user:email'],
    ],

Specified scopes are merged with the scopes already defined in the provider's class to ensure appropriate scopes are still submitted.

Tests written for default implementation and implementation with additional provided scopes.

End User Benefits

Instead of needing to alter the default implementation as described in The Official Documentation, users can simply add an array key to their configuration for the same affect.

Existing Features Considerations and Technical Notes

Updated SocialiteManager->buildProvider to initialise scopes from the configuration services.{driver}.scopes array if provided.

Added tests to validate GitHub driver behaves correctly with and without services.{driver}.scopes array provided.

Ensured scopes are returned as indexed arrays without missing indexes by using array_values to prevent possible future implementation issues.

Ensure backwards compatibility by wrapping provider instantiation in parenthesis when calling AbstractProvider->scopes() in SocialiteManager->buildProvider().

…ion.

Update `buildProvider` to initialize scopes from the configuration `services.{driver}.scopes` array if provided.
Add tests to validate GitHub driver behaves correctly with and without `services.{driver}.scopes` array provided in configuration.
Ensure scopes are returned as indexed arrays without missing indexes by using `array_values` to possibly prevent future implementation issues.
Ensure backwards compatibility by wrapping provider instantiation in parenthesis when calling scopes().
@taylorotwell taylorotwell merged commit b2ce47b into laravel:5.x Jan 16, 2025
25 checks passed
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