Skip to content

Commit

Permalink
Allow multiple client id for google
Browse files Browse the repository at this point in the history
  • Loading branch information
autowp committed Jul 20, 2018
1 parent 3afb3e8 commit ba42762
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

class Google extends AbstractService
{
/**
* @var Google_Client
*/
private $client = null;

/**
* @var string
*/
Expand All @@ -26,21 +21,6 @@ public function getState()
return '';
}

/**
* @return Google_Client
*/
public function getClient()
{
if (! $this->client) {
$this->client = new Google_Client([
'client_id' => $this->options['clientId']
]);
$this->client->addScope("email");
}

return $this->client;
}

/**
* @return string
*/
Expand Down Expand Up @@ -79,7 +59,23 @@ public function setIDToken(string $idToken)
*/
public function getData(array $options)
{
$payload = $this->getClient()->verifyIdToken($this->idToken);
$clientIDs = preg_split("/[[:space:]]+/isu", $this->options['clientId']);

foreach ($clientIDs as $clientID) {
if (! $clientID) {
continue;
}

$client = new Google_Client([
'client_id' => $clientID
]);

$payload = $client->verifyIdToken($this->idToken);
if ($payload) {
break;
}
}

if (! $payload) {
throw new Exception("idToken verification failed");
}
Expand Down

0 comments on commit ba42762

Please sign in to comment.