From f441bcf0315ba8d81ed233eec6927e397240ee81 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 18 Sep 2020 13:46:26 -0600 Subject: [PATCH] fix: add expires_in to default token callback (#1932) --- src/Google/Client.php | 1 + tests/Google/ClientTest.php | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Google/Client.php b/src/Google/Client.php index f33558f77..ee70dd48b 100644 --- a/src/Google/Client.php +++ b/src/Google/Client.php @@ -176,6 +176,7 @@ public function __construct(array $config = array()) $this->setAccessToken( [ 'access_token' => $newAccessToken, + 'expires_in' => 3600, // Google default 'created' => time(), ] ); diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index 3440102a3..3652b3ca6 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -702,9 +702,11 @@ public function testTokenCallback() // set the token callback to the client $client->setTokenCallback($callback); - // make a silly request to obtain a new token + // make a silly request to obtain a new token (it's ok if it fails) $http = $client->authorize(); - $http->get('https://www.googleapis.com/books/v1/volumes?q=Voltaire'); + try { + $http->get('https://www.googleapis.com/books/v1/volumes?q=Voltaire'); + } catch (Exception $e) {} $newToken = $client->getAccessToken(); // go back to the previous cache @@ -742,6 +744,8 @@ public function testDefaultTokenCallback() $accessToken['access_token'], $newToken['access_token'] ); + + $this->assertFalse($client->isAccessTokenExpired()); } public function testExecuteWithFormat()