Skip to content

Commit e097fbd

Browse files
authored
Merge pull request #1159 from google/fix/1158-oauth-client-token-callback
Provide client instance to token callback
2 parents ddcd425 + 29a2e1a commit e097fbd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

includes/Core/Authentication/Clients/OAuth_Client.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,15 @@ private function setup_client() {
264264

265265
// This is called when the client refreshes the access token on-the-fly.
266266
$client->setTokenCallback(
267-
function( $cache_key, $access_token ) {
267+
function( $cache_key, $access_token ) use ( $client ) {
268268
$expires_in = HOUR_IN_SECONDS; // Sane default, Google OAuth tokens are typically valid for an hour.
269269
$created = 0; // This will be replaced with the current timestamp when saving.
270270

271271
// Try looking up the real values if possible.
272-
if ( isset( $client ) ) {
273-
$token = $client->getAccessToken();
274-
if ( isset( $token['access_token'], $token['expires_in'], $token['created'] ) && $access_token === $token['access_token'] ) {
275-
$expires_in = $token['expires_in'];
276-
$created = $token['created'];
277-
}
272+
$token = $client->getAccessToken();
273+
if ( isset( $token['access_token'], $token['expires_in'], $token['created'] ) && $access_token === $token['access_token'] ) {
274+
$expires_in = $token['expires_in'];
275+
$created = $token['created'];
278276
}
279277

280278
$this->set_access_token( $access_token, $expires_in, $created );

0 commit comments

Comments
 (0)