Skip to content

Commit

Permalink
fix: add expires_in to default token callback (#1932)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored Sep 18, 2020
1 parent 752850b commit f441bcf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Google/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function __construct(array $config = array())
$this->setAccessToken(
[
'access_token' => $newAccessToken,
'expires_in' => 3600, // Google default
'created' => time(),
]
);
Expand Down
8 changes: 6 additions & 2 deletions tests/Google/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -742,6 +744,8 @@ public function testDefaultTokenCallback()
$accessToken['access_token'],
$newToken['access_token']
);

$this->assertFalse($client->isAccessTokenExpired());
}

public function testExecuteWithFormat()
Expand Down

0 comments on commit f441bcf

Please sign in to comment.