class ApplicationDefaultCredentials (View source)

ApplicationDefaultCredentials obtains the default credentials for authorizing a request to a Google service.

Application Default Credentials are described here: https://developers.google.com/accounts/docs/application-default-credentials

This class implements the search for the application default credentials as described in the link.

It provides three factory methods:

  • get returns the computed credentials object

  • getSubscriber returns an AuthTokenSubscriber built from the credentials object

  • getMiddleware returns an AuthTokenMiddleware built from the credentials object

This allows it to be used as follows with GuzzleHttp\Client:

use Google\Auth\ApplicationDefaultCredentials; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack;

$middleware = ApplicationDefaultCredentials::getMiddleware( 'https://www.googleapis.com/auth/taskqueue' ); $stack = HandlerStack::create(); $stack->push($middleware);

$client = new Client([ 'handler' => $stack, 'base_uri' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/', 'auth' => 'google_auth' // authorize all requests ]);

$res = $client->get('myproject/taskqueues/myqueue');

Methods

getSubscriber($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains an AuthTokenSubscriber that uses the default FetchAuthTokenInterface implementation to use in this environment.

getMiddleware($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains an AuthTokenMiddleware that uses the default FetchAuthTokenInterface implementation to use in this environment.

getCredentials($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains the default FetchAuthTokenInterface implementation to use in this environment.

Details

static AuthTokenSubscriber getSubscriber($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains an AuthTokenSubscriber that uses the default FetchAuthTokenInterface implementation to use in this environment.

If supplied, $scope is used to in creating the credentials instance if this does not fallback to the compute engine defaults.

Parameters

$scope
callable $httpHandler

callback which delivers psr7 request

array $cacheConfig

configuration for the cache when it's present

CacheItemPoolInterface $cache

an implementation of CacheItemPoolInterface

Return Value

AuthTokenSubscriber

Exceptions

DomainException

static AuthTokenMiddleware getMiddleware($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains an AuthTokenMiddleware that uses the default FetchAuthTokenInterface implementation to use in this environment.

If supplied, $scope is used to in creating the credentials instance if this does not fallback to the compute engine defaults.

Parameters

$scope
callable $httpHandler

callback which delivers psr7 request

array $cacheConfig

configuration for the cache when it's present

CacheItemPoolInterface $cache

Return Value

AuthTokenMiddleware

Exceptions

DomainException

static CredentialsLoader getCredentials($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)

Obtains the default FetchAuthTokenInterface implementation to use in this environment.

If supplied, $scope is used to in creating the credentials instance if this does not fallback to the Compute Engine defaults.

Parameters

$scope
callable $httpHandler

callback which delivers psr7 request

array $cacheConfig

configuration for the cache when it's present

CacheItemPoolInterface $cache

Return Value

CredentialsLoader

Exceptions

DomainException