1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Libraries/OAuth/Providers/Google.php

54 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Libraries\OAuth\Providers;
2020-10-28 11:10:49 +01:00
use Google_Client;
class Google implements ProviderInterface
{
public function getTokenResponse($token)
{
2020-10-28 11:10:49 +01:00
$client = new Google_Client();
return $client->verifyIdToken($token);
}
public function harvestEmail($payload)
{
return $payload['email'];
}
public function harvestSubField($payload)
{
return $payload['sub']; // user ID
}
2020-05-13 08:20:05 +02:00
public function harvestName($payload)
{
return $payload['name'];
}
public function harvestUser($access_token)
{
$client = new Google_Client();
$client->setClientId(config('ninja.auth.google.client_id'));
$client->setClientSecret(config('ninja.auth.google.client_secret'));
$client->setAccessToken($access_token);
$oauth2 = new \Google_Service_Oauth2($client);
try {
$userInfo = $oauth2->userinfo->get();
}
catch (\Exception $e) {
return false;
}
return [
'email' => $userInfo['email'],
'sub' => $userInfo['id'],
'name' => $userInfo['name'],
];
}
}