Skip to content

Commit 8cee80a

Browse files
Adam Rodriguezramsey
authored andcommitted
fix for invalid expires value
Cherry-picked from #929
1 parent 3c8c2b4 commit 8cee80a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Token/AccessToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function __construct(array $options = [])
118118
} elseif (!empty($options['expires'])) {
119119
// Some providers supply the seconds until expiration rather than
120120
// the exact timestamp. Take a best guess at which we received.
121-
$expires = $options['expires'];
121+
$expires = (int) $options['expires'];
122122

123123
if (!$this->isExpirationTimestamp($expires)) {
124124
$expires += $this->getTimeNow();

test/src/Token/AccessTokenTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,32 @@ public function testInvalidExpiresIn()
222222
self::tearDownForBackwardsCompatibility();
223223
}
224224

225+
public function testInvalidExpiresWhenExpiresDoesNotCastToInteger()
226+
{
227+
$options = [
228+
'access_token' => 'access_token',
229+
'expires' => 'TEXT',
230+
];
231+
232+
$token = $this->getAccessToken($options);
233+
234+
$this->assertSame($token->getTimeNow(), $token->getExpires());
235+
}
236+
237+
public function testInvalidExpiresWhenExpiresCastsToInteger()
238+
{
239+
$options = [
240+
'access_token' => 'access_token',
241+
'expires' => '3TEXT',
242+
];
243+
244+
$token = $this->getAccessToken($options);
245+
246+
$this->assertSame($token->getTimeNow() + 3, $token->getExpires());
247+
$this->assertFalse($token->hasExpired());
248+
249+
self::tearDownForBackwardsCompatibility();
250+
}
225251

226252
public function testJsonSerializable()
227253
{

0 commit comments

Comments
 (0)