2020-05-16 04:04:24 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-05-16 04:04:24 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-05-16 04:04:24 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Libraries\Google;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
use Google_Client;
|
|
|
|
|
2020-05-16 04:04:24 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class Google.
|
2020-05-16 04:04:24 +02:00
|
|
|
*/
|
|
|
|
class Google
|
|
|
|
{
|
|
|
|
public $client;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$this->client = new Google_Client();
|
2020-05-16 04:04:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->client->setClientId(config('ninja.auth.google.client_id'));
|
|
|
|
$this->client->setClientSecret(config('ninja.auth.google.client_secret'));
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClient()
|
|
|
|
{
|
|
|
|
return $this->client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkAccessToken()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function refreshToken($user)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if ($this->client->isAccessTokenExpired()) {
|
2020-05-16 04:04:24 +02:00
|
|
|
$this->client->fetchAccessTokenWithRefreshToken($user->oauth_user_refresh_token);
|
|
|
|
|
|
|
|
$access_token = $this->client->getAccessToken();
|
|
|
|
|
2020-05-16 12:26:16 +02:00
|
|
|
$user->oauth_user_token = $access_token;
|
2020-05-16 04:04:24 +02:00
|
|
|
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|