2020-04-15 02:30:52 +02:00
|
|
|
<?php
|
2020-04-06 14:32:27 +02:00
|
|
|
|
|
|
|
namespace App\Libraries\OAuth\Providers;
|
2019-05-22 05:18:18 +02:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
use Google_Client;
|
2019-05-22 05:18:18 +02:00
|
|
|
class Google implements ProviderInterface
|
|
|
|
{
|
|
|
|
public function getTokenResponse($token)
|
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$client = new Google_Client();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-05-22 05:18:18 +02:00
|
|
|
return $client->verifyIdToken($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function harvestEmail($payload)
|
|
|
|
{
|
|
|
|
return $payload['email'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function harvestSubField($payload)
|
|
|
|
{
|
|
|
|
return $payload['sub']; // user ID
|
|
|
|
}
|
2020-05-13 06:51:16 +02:00
|
|
|
|
2020-05-13 08:20:05 +02:00
|
|
|
public function harvestName($payload)
|
2020-05-13 06:51:16 +02:00
|
|
|
{
|
|
|
|
return $payload['name'];
|
|
|
|
}
|
2023-11-21 00:50:19 +01:00
|
|
|
|
|
|
|
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'],
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
2019-05-22 05:18:18 +02:00
|
|
|
}
|