coderello / laravel-passport-social-grant

🔒 API authentication via social networks for your Laravel application
https://packagist.org/packages/coderello/laravel-passport-social-grant
MIT License
174 stars 20 forks source link

Fix for '*' scope not being set for issued tokens #30

Closed alibarthi closed 4 years ago

alibarthi commented 4 years ago

Hi,

Global '*' scope is not set when issuing tokens, because the social grant is not a valid grantType in Laravel\Passport\Bridge\ScopeRepository, the finalizeScopes function: https://github.com/laravel/passport/blob/63c8b6645b2503af10ae3f64938c12b2790ac753/src/Bridge/ScopeRepository.php#L24

public function finalizeScopes(
        array $scopes, $grantType,
        ClientEntityInterface $clientEntity, $userIdentifier = null)
    {
        if (! in_array($grantType, ['password', 'personal_access', 'client_credentials'])) {
            $scopes = collect($scopes)->reject(function ($scope) {
                return trim($scope->getIdentifier()) === '*';
            })->values()->all();
        }
    ...
    }

With this proposed change, we can simply finalizeScopes as for the 'password' grant, since social grant is based on it anyway.

Maybe fixes #20 where default scope is not being set on tokens