1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Libraries/Google/Google.php
David Bomba d05bd7d2c1
Test for Gmail (#3706)
* Fixes for null values in custom values

* Refactor mailing

* Working on send emails from GMail API

* Fixes for tests

* Test for GMail
2020-05-16 12:04:24 +10:00

66 lines
1.4 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Libraries\Google;
/**
* Class Google
* @package App\Libraries\Google
*/
class Google
{
public $client;
public function __construct()
{
$this->client = new \Google_Client();
}
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)
{
if($this->client->isAccessTokenExpired()) {
$this->client->fetchAccessTokenWithRefreshToken($user->oauth_user_refresh_token);
$access_token = $this->client->getAccessToken();
if(is_string($access_token))
$user->oauth_user_token = $access_token;
elseif(isset($access_token['access_token']))
$user->oauth_user_token = $access_token['access_token']);
$user->save();
$this->client->setAccessToken($access_token);
}
return $this;
}
}