Skip to content

Commit e96471b

Browse files
authored
fix: check token expires_in attribute (googleapis#2218)
1 parent a18b0e1 commit e96471b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ public function isAccessTokenExpired()
569569
}
570570
}
571571
}
572+
if (!isset($this->token['expires_in'])) {
573+
// if the token does not have an "expires_in", then it's considered expired
574+
return true;
575+
}
572576

573577
// If the token is set to expire in the next 30 seconds.
574578
return ($created + ($this->token['expires_in'] - 30)) < time();

tests/Google/ClientTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ public function testSettersGetters()
315315
$this->assertEquals($token, $client->getAccessToken());
316316
}
317317

318+
public function testSetAccessTokenValidation()
319+
{
320+
$client = new Client();
321+
$client->setAccessToken([
322+
'access_token' => 'token',
323+
'created' => time()
324+
]);
325+
self::assertEquals(true, $client->isAccessTokenExpired());
326+
}
327+
318328
public function testDefaultConfigOptions()
319329
{
320330
$client = new Client();

0 commit comments

Comments
 (0)