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

(feat) Extract some logic to a userInstance method. #663

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

lucasmichot
Copy link
Contributor

This PR extracts some of the logic of the \Laravel\Socialite\Two\AbstractProvider::user() method into a new \Laravel\Socialite\Two\AbstractProvider::userInstance() method.

Nothing changes, but each provider can now override userInstance() and had some extra logic or retrieve additional data.

Probably one of the first use case could be for the GitHub provider and its new expiring tokens: the token response now comes with a new field called refresh_token_expires_in (possibly null), that will can now be attached to the user in a simple way:

// in src/Two/GithubProvider.php
/**
 * {@inheritdoc}
 */
function userInstance(array $response, array $user)
{
    $this->user = parent::userInstance($response, $user);
    $this->user->refreshTokenExpiresIn = $response['refresh_token_expires_in'] ?? null;

    return $this->user;
}

Note:
I am not opinionated concerning the name of this method, that could be renamed.

@taylorotwell taylorotwell merged commit 49ecc4c into laravel:5.x Sep 7, 2023
18 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