ostap liked this thread
Hello,
I had the same problem, solved it by creating a helper class using the Google PHP API. Unfortunately socialite is pretty bare in functionality.
This is the specific function in my helper class handling refresh tokens, you would have to make some adjustments.
/**
* Refresh User's Google OAuth2 Access Token
*
* @param [type] $oauth2 [description]
* @return [type] [description]
*/
protected static function refreshGoogle($oauth2)
{
$config = Config('services.google');
// Config
$client_id = $config['client_id'];
$client_secret = $config['client_secret'];
// User
$token = $oauth2->{'auth.token'};
$refreshToken = $oauth2->{'auth.refreshToken'};
$expiresIn = $oauth2->{'auth.expiresIn'};
// Time
$current = Carbon::now();
$expired = $oauth2->updated_at->addSeconds($expiresIn);
// If current date exceeds expired date request new access token
if($current > $expired) {
// Set Client
$client = new Google_Client;
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->refreshToken($refreshToken);
$client->setAccessType('offline');
return $client->getAccessToken();
}
return false;
}
ostap liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community