Copied!

A class to implement caching for any object implementing FetchAuthTokenInterface

CloneableInstantiable
Constants
public Google\Auth\UpdateMetadataInterface::AUTH_METADATA_KEY = 'authorization'
public Google\Auth\GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN = 'googleapis.com'
public Google\Auth\GetQuotaProjectInterface::X_GOOG_USER_PROJECT_HEADER = 'X-Goog-User-Project'
Methods
public __construct(Google\Auth\FetchAuthTokenInterface $fetcher, ?array $cacheConfig = NULL, ?Psr\Cache\CacheItemPoolInterface $cache = NULL)
 
  • param \FetchAuthTokenInterface $fetcher A credentials fetcher
  • param array|null $cacheConfig Configuration for the cache
  • param \CacheItemPoolInterface $cache
public fetchAuthToken(?callable $httpHandler = NULL)
 

Implements FetchAuthTokenInterface#fetchAuthToken.

Checks the cache for a valid auth token and fetches the auth tokens from the supplied fetcher.

  • param callable|null $httpHandler callback which delivers psr7 request
  • return array the response
  • throws \Exception
public getCacheKey()
 
  • return string
public getClientName(?callable $httpHandler = NULL)
 

Get the client name from the fetcher.

  • param callable|null $httpHandler An HTTP handler to deliver PSR7 requests.
  • return string
public getFetcher()
 
  • return \FetchAuthTokenInterface
public getLastReceivedToken()
 
  • return array|null
public getProjectId(?callable $httpHandler = NULL)
 

Get the Project ID from the fetcher.

  • param callable|null $httpHandler Callback which delivers psr7 request
  • return string|null
  • throws \RuntimeException If the fetcher does not implement Google\Auth\ProvidesProjectIdInterface.
public getQuotaProject()
 

Get the quota project used for this API request from the credentials fetcher.

  • return string|null
public getUniverseDomain() : string
public signBlob( $stringToSign, $forceOpenSsl = false)
 

Sign a blob using the fetcher.

  • param string $stringToSign The string to sign.
  • param bool $forceOpenSsl Require use of OpenSSL for local signing. Does not apply to signing done using external services. Defaults to false.
  • return string The resulting signature.
  • throws \RuntimeException If the fetcher does not implement Google\Auth\SignBlobInterface.
public updateMetadata( $metadata, $authUri = NULL, ?callable $httpHandler = NULL)
 

Updates metadata with the authorization token.

  • param array $metadata metadata hashmap
  • param string $authUri optional auth uri
  • param callable|null $httpHandler callback which delivers psr7 request
  • return array updated metadata hashmap
  • throws \RuntimeException If the fetcher does not implement Google\Auth\UpdateMetadataInterface.
Properties
private $cache = NULL
 
  • var ?\CacheItemPoolInterface
private $cacheConfig = NULL
 
  • var array
private $eagerRefreshThresholdSeconds = 10
 
  • var int
private $fetcher = NULL
 
  • var \FetchAuthTokenInterface
private $maxKeyLength = 64
 
  • var int
Methods
private fetchAuthTokenFromCache( $authUri = NULL)
 
  • param string|null $authUri
  • return array|null
private getCachedUniverseDomain(Google\Auth\GetUniverseDomainInterface $fetcher) : string
private getCachedValue( $k)
 

Gets the cached value if it is present in the cache when that is available.

  • param mixed $k
  • return mixed
private getFullCacheKey( $key)
 
  • param null|string $key
  • return null|string
private saveAuthTokenInCache( $authToken, $authUri = NULL)
 
  • param array $authToken
  • param string|null $authUri
  • return void
private setCachedValue( $k, $v)
 

Saves the value in the cache when that is available.

  • param mixed $k
  • param mixed $v
  • return mixed
© 2025 Bruce Wells