From 12a6ad5463218be985109f47d28feea2a58a5a60 Mon Sep 17 00:00:00 2001 From: Adam Rodriguez Date: Fri, 17 Dec 2021 14:01:27 -0700 Subject: [PATCH] fix for invalid expires value --- src/Token/AccessToken.php | 4 ++++ test/src/Token/AccessTokenTest.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 81533c30..51bbc6f4 100644 --- a/src/Token/AccessToken.php +++ b/src/Token/AccessToken.php @@ -121,6 +121,10 @@ public function __construct(array $options = []) $expires = $options['expires']; if (!$this->isExpirationTimestamp($expires)) { + if (!is_numeric($expires)) { + $expires = intval($expires); + } + $expires += $this->getTimeNow(); } diff --git a/test/src/Token/AccessTokenTest.php b/test/src/Token/AccessTokenTest.php index 23ad105f..29f02478 100644 --- a/test/src/Token/AccessTokenTest.php +++ b/test/src/Token/AccessTokenTest.php @@ -189,6 +189,28 @@ public function testInvalidExpiresIn() self::tearDownForBackwardsCompatibility(); } + public function testInvalidExpires() + { + $options = [ + 'access_token' => 'access_token', + 'expires' => 'TEXT', + ]; + + $token = $this->getAccessToken($options); + + $this->assertSame($token->getExpires(), $token->getTimeNow()); + + $options = [ + 'access_token' => 'access_token', + 'expires' => '3TEXT', + ]; + + $token = $this->getAccessToken($options); + + $this->assertFalse($token->hasExpired()); + + self::tearDownForBackwardsCompatibility(); + } public function testJsonSerializable() {