From e7e8a8b554ef0c3e2267155db01bf85d611c5779 Mon Sep 17 00:00:00 2001 From: Daniel Alm Date: Fri, 23 Apr 2021 18:16:01 +0200 Subject: [PATCH] feat: Allow RequestWrapperTrait to use its auth cache when fetching ADC (#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 * Update RequestWrapperTrait.php Co-authored-by: Brent Shaffer --- src/RequestWrapperTrait.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/RequestWrapperTrait.php b/src/RequestWrapperTrait.php index 65aa189..887f26e 100644 --- a/src/RequestWrapperTrait.php +++ b/src/RequestWrapperTrait.php @@ -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 + ); + } } /** @@ -196,8 +202,8 @@ protected function getADC() return ApplicationDefaultCredentials::getCredentials( $this->scopes, $this->authHttpHandler, - null, - null, + $this->authCacheOptions, + $this->authCache, $this->quotaProject ); }