Skip to content

Commit

Permalink
fix for invalid expires value
Browse files Browse the repository at this point in the history
Cherry-picked from #929
  • Loading branch information
Adam Rodriguez authored and ramsey committed Dec 11, 2024
1 parent 3c8c2b4 commit 8cee80a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Token/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function __construct(array $options = [])
} elseif (!empty($options['expires'])) {
// Some providers supply the seconds until expiration rather than
// the exact timestamp. Take a best guess at which we received.
$expires = $options['expires'];
$expires = (int) $options['expires'];

if (!$this->isExpirationTimestamp($expires)) {
$expires += $this->getTimeNow();
Expand Down
26 changes: 26 additions & 0 deletions test/src/Token/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ public function testInvalidExpiresIn()
self::tearDownForBackwardsCompatibility();
}

public function testInvalidExpiresWhenExpiresDoesNotCastToInteger()
{
$options = [
'access_token' => 'access_token',
'expires' => 'TEXT',
];

$token = $this->getAccessToken($options);

$this->assertSame($token->getTimeNow(), $token->getExpires());
}

public function testInvalidExpiresWhenExpiresCastsToInteger()
{
$options = [
'access_token' => 'access_token',
'expires' => '3TEXT',
];

$token = $this->getAccessToken($options);

$this->assertSame($token->getTimeNow() + 3, $token->getExpires());
$this->assertFalse($token->hasExpired());

self::tearDownForBackwardsCompatibility();
}

public function testJsonSerializable()
{
Expand Down

0 comments on commit 8cee80a

Please sign in to comment.