Copied!

The CredentialsWrapper object provides a wrapper around a FetchAuthTokenInterface.

CloneableInstantiable
Methods
public __construct(Google\Auth\FetchAuthTokenInterface $credentialsFetcher, ?callable $authHttpHandler = NULL, string $universeDomain = 'googleapis.com'Google\Auth\GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN)
 

CredentialsWrapper constructor.

  • param \FetchAuthTokenInterface $credentialsFetcher A credentials loader used to fetch access tokens.
  • param callable $authHttpHandler A handler used to deliver PSR-7 requests specifically for authentication. Should match a signature of function (RequestInterface $request, array $options) : ResponseInterface.
  • throws \ValidationException
public static build(array $args = [], string $universeDomain = 'googleapis.com'Google\Auth\GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN)
 

Factory method to create a CredentialsWrapper from an array of options.

  • param array $args { An array of optional arguments.
    @type string|array $keyFile
          Credentials to be used. Accepts either a path to a credentials file, or a decoded
          credentials file as a PHP array. If this is not specified, application default
          credentials will be used.
    @type string[] $scopes
          A string array of scopes to use when acquiring credentials.
    @type callable $authHttpHandler
          A handler used to deliver PSR-7 requests specifically
          for authentication. Should match a signature of
          `function (RequestInterface $request, array $options) : ResponseInterface`.
    @type bool $enableCaching
          Enable caching of access tokens. Defaults to true.
    @type CacheItemPoolInterface $authCache
          A cache for storing access tokens. Defaults to a simple in memory implementation.
    @type array $authCacheOptions
          Cache configuration options.
    @type string $quotaProject
          Specifies a user project to bill for access charges associated with the request.
    @type string[] $defaultScopes
          A string array of default scopes to use when acquiring
          credentials.
    @type bool $useJwtAccessWithScope
          Ensures service account credentials use JWT Access (also known as self-signed
          JWTs), even when user-defined scopes are supplied.
    
    }
  • param string $universeDomain The expected universe of the credentials. Defaults to "googleapis.com"
  • return \CredentialsWrapper
  • throws \ValidationException
public checkUniverseDomain() : void
 

Verify that the expected universe domain matches the universe domain from the credentials.

  • throws \ValidationException if the universe domain does not match.
public getAuthorizationHeaderCallback( $audience = NULL) : ?callable
 
  • param string $audience optional audience for self-signed JWTs.
  • return callable Callable function that returns an authorization header.
public getBearerString()
 
  • deprecated
  • return string Bearer string containing access token.
public getProjectId(?callable $httpHandler = NULL) : ?string
public getQuotaProject() : ?string
 
  • return string|null The quota project associated with the credentials.
public static validate(array $arr, array $requiredKeys)
 
  • param array $arr Associative array
  • param array $requiredKeys List of keys to check for in $arr
  • return array Returns $arr for fluent use
public static validateNotNull(array $arr, array $requiredKeys)
 
  • param array $arr Associative array
  • param array $requiredKeys List of keys to check for in $arr
  • return array Returns $arr for fluent use
Properties
private $authHttpHandler = NULL
 
  • var callable $authHttpHandle
private ?Google\Auth\FetchAuthTokenInterface $credentialsFetcher = NULL
 
  • var \FetchAuthTokenInterface $credentialsFetcher
private static int $eagerRefreshThresholdSeconds = 10
 
  • var int
private bool $hasCheckedUniverse = false
private string $universeDomain
Methods
private static buildApplicationDefaultCredentials(?array $scopes = NULL, ?callable $authHttpHandler = NULL, ?array $authCacheOptions = NULL, ?Psr\Cache\CacheItemPoolInterface $authCache = NULL, $quotaProject = NULL, ?array $defaultScopes = NULL)
 
  • param array $scopes
  • param callable $authHttpHandler
  • param array $authCacheOptions
  • param \CacheItemPoolInterface $authCache
  • param string $quotaProject
  • param array $defaultScopes
  • return \FetchAuthTokenInterface
  • throws \ValidationException
private static isExpired( $token)
 
  • param mixed $token
private static isValid( $token)
 
  • param mixed $token
private shouldCheckUniverseDomain() : bool
 

Skip universe domain check for Metadata server (e.g. GCE) credentials.

  • return bool
private static validateFileExists(string $filePath)
 
  • param string $filePath
  • throws \ValidationException
private static validateImpl( $arr, $requiredKeys, $allowNull)
Properties
private static int $eagerRefreshThresholdSeconds = 10
 
  • var int
Methods
public static build(array $args = [], string $universeDomain = 'googleapis.com'Google\Auth\GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN)
 

Factory method to create a CredentialsWrapper from an array of options.

  • param array $args { An array of optional arguments.
    @type string|array $keyFile
          Credentials to be used. Accepts either a path to a credentials file, or a decoded
          credentials file as a PHP array. If this is not specified, application default
          credentials will be used.
    @type string[] $scopes
          A string array of scopes to use when acquiring credentials.
    @type callable $authHttpHandler
          A handler used to deliver PSR-7 requests specifically
          for authentication. Should match a signature of
          `function (RequestInterface $request, array $options) : ResponseInterface`.
    @type bool $enableCaching
          Enable caching of access tokens. Defaults to true.
    @type CacheItemPoolInterface $authCache
          A cache for storing access tokens. Defaults to a simple in memory implementation.
    @type array $authCacheOptions
          Cache configuration options.
    @type string $quotaProject
          Specifies a user project to bill for access charges associated with the request.
    @type string[] $defaultScopes
          A string array of default scopes to use when acquiring
          credentials.
    @type bool $useJwtAccessWithScope
          Ensures service account credentials use JWT Access (also known as self-signed
          JWTs), even when user-defined scopes are supplied.
    
    }
  • param string $universeDomain The expected universe of the credentials. Defaults to "googleapis.com"
  • return \CredentialsWrapper
  • throws \ValidationException
private static buildApplicationDefaultCredentials(?array $scopes = NULL, ?callable $authHttpHandler = NULL, ?array $authCacheOptions = NULL, ?Psr\Cache\CacheItemPoolInterface $authCache = NULL, $quotaProject = NULL, ?array $defaultScopes = NULL)
 
  • param array $scopes
  • param callable $authHttpHandler
  • param array $authCacheOptions
  • param \CacheItemPoolInterface $authCache
  • param string $quotaProject
  • param array $defaultScopes
  • return \FetchAuthTokenInterface
  • throws \ValidationException
private static isExpired( $token)
 
  • param mixed $token
private static isValid( $token)
 
  • param mixed $token
public static validate(array $arr, array $requiredKeys)
 
  • param array $arr Associative array
  • param array $requiredKeys List of keys to check for in $arr
  • return array Returns $arr for fluent use
private static validateFileExists(string $filePath)
 
  • param string $filePath
  • throws \ValidationException
private static validateImpl( $arr, $requiredKeys, $allowNull)
public static validateNotNull(array $arr, array $requiredKeys)
 
  • param array $arr Associative array
  • param array $requiredKeys List of keys to check for in $arr
  • return array Returns $arr for fluent use
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration