PluginProbe
Authorizer / 3.6.0
Authorizer v3.6.0
3.16.0 3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 All 127 releases
← All changes | vendor/google/auth/src/FetchAuthTokenCache.php +16 -71 3.14.23.6.0 View file →
@@ -25,9 +25,8 @@
25 25 */
26 26 class FetchAuthTokenCache implements
27 27 FetchAuthTokenInterface,
28 28 GetQuotaProjectInterface,
29 - GetUniverseDomainInterface,
30 29 SignBlobInterface,
31 30 ProjectIdProviderInterface,
32 31 UpdateMetadataInterface
33 32 {
@@ -44,15 +43,15 @@
44 43 private $eagerRefreshThresholdSeconds = 10;
45 44
46 45 /**
47 46 * @param FetchAuthTokenInterface $fetcher A credentials fetcher
48 - * @param array<mixed>|null $cacheConfig Configuration for the cache
47 + * @param array<mixed> $cacheConfig Configuration for the cache
49 48 * @param CacheItemPoolInterface $cache
50 49 */
51 50 public function __construct(
52 51 FetchAuthTokenInterface $fetcher,
53 - ?array $cacheConfig = null,
54 - ?CacheItemPoolInterface $cache = null
52 + array $cacheConfig = null,
53 + CacheItemPoolInterface $cache
55 54 ) {
56 55 $this->fetcher = $fetcher;
57 56 $this->cache = $cache;
58 57 $this->cacheConfig = array_merge([
@@ -57,31 +56,22 @@
57 56 $this->cache = $cache;
58 57 $this->cacheConfig = array_merge([
59 58 'lifetime' => 1500,
60 59 'prefix' => '',
61 - 'cacheUniverseDomain' => $fetcher instanceof Credentials\GCECredentials,
62 60 ], (array) $cacheConfig);
63 61 }
64 62
65 63 /**
66 - * @return FetchAuthTokenInterface
67 - */
68 - public function getFetcher()
69 - {
70 - return $this->fetcher;
71 - }
72 -
73 - /**
74 64 * Implements FetchAuthTokenInterface#fetchAuthToken.
75 65 *
76 66 * Checks the cache for a valid auth token and fetches the auth tokens
77 67 * from the supplied fetcher.
78 68 *
79 - * @param callable|null $httpHandler callback which delivers psr7 request
69 + * @param callable $httpHandler callback which delivers psr7 request
80 70 * @return array<mixed> the response
81 71 * @throws \Exception
82 72 */
83 - public function fetchAuthToken(?callable $httpHandler = null)
73 + public function fetchAuthToken(callable $httpHandler = null)
84 74 {
85 75 if ($cached = $this->fetchAuthTokenFromCache()) {
86 76 return $cached;
87 77 }
@@ -111,12 +101,12 @@
111 101
112 102 /**
113 103 * Get the client name from the fetcher.
114 104 *
115 - * @param callable|null $httpHandler An HTTP handler to deliver PSR7 requests.
105 + * @param callable $httpHandler An HTTP handler to deliver PSR7 requests.
116 106 * @return string
117 107 */
118 - public function getClientName(?callable $httpHandler = null)
108 + public function getClientName(callable $httpHandler = null)
119 109 {
120 110 if (!$this->fetcher instanceof SignBlobInterface) {
121 111 throw new \RuntimeException(
122 112 'Credentials fetcher does not implement ' .
@@ -146,16 +136,13 @@
146 136 'Google\Auth\SignBlobInterface'
147 137 );
148 138 }
149 139
150 - // Pass the access token from cache for credentials that sign blobs
151 - // using the IAM API. This saves a call to fetch an access token when a
152 - // cached token exists.
153 - if ($this->fetcher instanceof Credentials\GCECredentials
154 - || $this->fetcher instanceof Credentials\ImpersonatedServiceAccountCredentials
155 - ) {
140 + // Pass the access token from cache to GCECredentials for signing a blob.
141 + // This saves a call to the metadata server when a cached token exists.
142 + if ($this->fetcher instanceof Credentials\GCECredentials) {
156 143 $cached = $this->fetchAuthTokenFromCache();
157 - $accessToken = $cached['access_token'] ?? null;
144 + $accessToken = isset($cached['access_token']) ? $cached['access_token'] : null;
158 145 return $this->fetcher->signBlob($stringToSign, $forceOpenSsl, $accessToken);
159 146 }
160 147
161 148 return $this->fetcher->signBlob($stringToSign, $forceOpenSsl);
@@ -175,17 +162,17 @@
175 162
176 163 return null;
177 164 }
178 165
179 - /**
166 + /*
180 167 * Get the Project ID from the fetcher.
181 168 *
182 - * @param callable|null $httpHandler Callback which delivers psr7 request
169 + * @param callable $httpHandler Callback which delivers psr7 request
183 170 * @return string|null
184 171 * @throws \RuntimeException If the fetcher does not implement
185 172 * `Google\Auth\ProvidesProjectIdInterface`.
186 173 */
187 - public function getProjectId(?callable $httpHandler = null)
174 + public function getProjectId(callable $httpHandler = null)
188 175 {
189 176 if (!$this->fetcher instanceof ProjectIdProviderInterface) {
190 177 throw new \RuntimeException(
191 178 'Credentials fetcher does not implement ' .
@@ -192,43 +179,17 @@
192 179 'Google\Auth\ProvidesProjectIdInterface'
193 180 );
194 181 }
195 182
196 - // Pass the access token from cache for credentials that require an
197 - // access token to fetch the project ID. This saves a call to fetch an
198 - // access token when a cached token exists.
199 - if ($this->fetcher instanceof Credentials\ExternalAccountCredentials) {
200 - $cached = $this->fetchAuthTokenFromCache();
201 - $accessToken = $cached['access_token'] ?? null;
202 - return $this->fetcher->getProjectId($httpHandler, $accessToken);
203 - }
204 -
205 183 return $this->fetcher->getProjectId($httpHandler);
206 184 }
207 185
208 - /*
209 - * Get the Universe Domain from the fetcher.
210 - *
211 - * @return string
212 - */
213 - public function getUniverseDomain(): string
214 - {
215 - if ($this->fetcher instanceof GetUniverseDomainInterface) {
216 - if ($this->cacheConfig['cacheUniverseDomain']) {
217 - return $this->getCachedUniverseDomain($this->fetcher);
218 - }
219 - return $this->fetcher->getUniverseDomain();
220 - }
221 -
222 - return GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN;
223 - }
224 -
225 186 /**
226 187 * Updates metadata with the authorization token.
227 188 *
228 189 * @param array<mixed> $metadata metadata hashmap
229 190 * @param string $authUri optional auth uri
230 - * @param callable|null $httpHandler callback which delivers psr7 request
191 + * @param callable $httpHandler callback which delivers psr7 request
231 192 * @return array<mixed> updated metadata hashmap
232 193 * @throws \RuntimeException If the fetcher does not implement
233 194 * `Google\Auth\UpdateMetadataInterface`.
234 195 */
@@ -234,9 +195,9 @@
234 195 */
235 196 public function updateMetadata(
236 197 $metadata,
237 198 $authUri = null,
238 - ?callable $httpHandler = null
199 + callable $httpHandler = null
239 200 ) {
240 201 if (!$this->fetcher instanceof UpdateMetadataInterface) {
241 202 throw new \RuntimeException(
242 203 'Credentials fetcher does not implement ' .
@@ -252,12 +213,8 @@
252 213 if (isset($cached['access_token'])) {
253 214 $metadata[self::AUTH_METADATA_KEY] = [
254 215 'Bearer ' . $cached['access_token']
255 216 ];
256 - } elseif (isset($cached['id_token'])) {
257 - $metadata[self::AUTH_METADATA_KEY] = [
258 - 'Bearer ' . $cached['id_token']
259 - ];
260 217 }
261 218 }
262 219
263 220 $newMetadata = $this->fetcher->updateMetadata(
@@ -322,18 +279,6 @@
322 279 : $this->fetcher->getCacheKey();
323 280
324 281 $this->setCachedValue($cacheKey, $authToken);
325 282 }
326 - }
327 -
328 - private function getCachedUniverseDomain(GetUniverseDomainInterface $fetcher): string
329 - {
330 - $cacheKey = $this->getFullCacheKey($fetcher->getCacheKey() . 'universe_domain'); // @phpstan-ignore-line
331 - if ($universeDomain = $this->getCachedValue($cacheKey)) {
332 - return $universeDomain;
333 - }
334 -
335 - $universeDomain = $fetcher->getUniverseDomain();
336 - $this->setCachedValue($cacheKey, $universeDomain);
337 - return $universeDomain;
338 283 }
339 284 }