Skip to content

Commit

Permalink
feat: Allow RequestWrapperTrait to use its auth cache when fetching A…
Browse files Browse the repository at this point in the history
…DC (#3959)

* feat: Allow RequestWrapperTrait to use the its auth cache when fetching ADC

* Avoid nested `FetchAuthTokenCache`s.

* Use instanceof instead of is_a

Co-authored-by: Brent Shaffer <[email protected]>

* Update RequestWrapperTrait.php

Co-authored-by: Brent Shaffer <[email protected]>
  • Loading branch information
MrMage and bshaffer authored Apr 23, 2021
1 parent 1181c07 commit e7e8a8b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/RequestWrapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ public function getCredentialsFetcher()
}
}

return new FetchAuthTokenCache(
$fetcher,
$this->authCacheOptions,
$this->authCache
);
if ($fetcher instanceof FetchAuthTokenCache) {
// The fetcher has already been wrapped in a cache by `ApplicationDefaultCredentials`;
// no need to wrap it another time.
return $fetcher;
} else {
return new FetchAuthTokenCache(
$fetcher,
$this->authCacheOptions,
$this->authCache
);
}
}

/**
Expand All @@ -196,8 +202,8 @@ protected function getADC()
return ApplicationDefaultCredentials::getCredentials(
$this->scopes,
$this->authHttpHandler,
null,
null,
$this->authCacheOptions,
$this->authCache,
$this->quotaProject
);
}
Expand Down

0 comments on commit e7e8a8b

Please sign in to comment.