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

Set the scopes on the Socialite\User instance #568

Closed
vanyamil opened this issue Dec 3, 2021 · 2 comments
Closed

Set the scopes on the Socialite\User instance #568

vanyamil opened this issue Dec 3, 2021 · 2 comments

Comments

@vanyamil
Copy link

vanyamil commented Dec 3, 2021

Hello,

I am currently working on mixing custom Google API calls alongside the existing Socialite implementation. As part of requesting additional scopes (using Google's incremental authorization), I would like the possibility of seeing all scopes given by the current access token. These are returned in the ->getAccessTokenResponse() method under the scope method.

Since this is part of the guidelines on the access token response (OAuth2 simplified), I think it would be beneficial to add this to the whole AbstractProvider class. I'm not good at PRs so some ideas here:

In Two/AbstractProvider.php@user, before the return, add

if(Arr::exists($response, 'scope'))
    $this->user->setScopes(explode($this->scopeSeparator, Arr::get($response, 'scope')))

In Two/User.php, add a new method and field:

    /**
     * The user's granted scopes.
     *
     * @var array
     */
    public $scopes;

    /**
     * Set the scopes that the access token has permission for.
     *
     * @param  array $scopes
     * @return $this
     */
    public function setScopes($scopes)
    {
        $this->scopes = $scopes;

        return $this;
    }

The only missing part of the puzzle is how to track which scopes should be set if the scopes match what was requested and no scopes field is placed. It looks like we'd have to insert the requested scopes into the session and pull() them like the state? But maybe I'm not seeing the correct approach here

Thanks!

@vanyamil
Copy link
Author

vanyamil commented Dec 3, 2021

If we do store the scopes into session, then we won't even need the Arr::exists check - just set the default value on the Arr::get to be the $this->request->session()->pull('scopes')

@driesvints
Copy link
Member

Heya, I'm sorry but we currently do not have plans to work on something like this ourselves. You can always attempt a PR or look around for someone willing to co-create one. Thanks

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

No branches or pull requests

2 participants