Laravel Socialite update

access_token

acquired by Socialite (via Socialite::driver(self::PROVIDER)->user()

has a limited time value. For Google it is an hour.

I can get refresh_token

by changing the redirect call to:

Socialite::driver(self::PROVIDER)->stateless()->with([
    'access_type' => 'offline',
])->redirect()

      

Within an hour, I can read user data based on access_token

by calling

// $token = read_stored_access_token()
\Socialite::driver(self::PROVIDER)->userFromToken($accessToken);

      

An hour later, when the token becomes invalid, the Google API starts returning 401 Unauthorized

and Socialize propagates this:

(1/1) ClientException
Client error: `GET https://www.googleapis.com/plus/v1/people/me?prettyPrint=false` resulted in a `401 Unauthorized` response:
{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","loc (truncated...)

      

Now with refresh_token

I should easily update access_token

. But I can't find any mention in the Socialize docs or source code that would allow me to do this.

Is this really the only way how to do it, use the Google API library and do it manually? Doesn't that kill the whole idea of ​​using Socialize?

Note. I am trying to avoid being called again redirect()

as it might force the user to choose one of their Google accounts every day. This is annoying.

Thank!

+3


source to share





All Articles