Reference documentation and code samples for the Google Auth Library Client class ApplicationDefaultCredentials.
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');
Namespace
Google \ AuthMethods
static::getSubscriber
scope
string|string[]
the scope of the access request, expressed either as an Array or as a space-delimited String.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
Subscriber\AuthTokenSubscriber
static::getMiddleware
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.
scope
string|string[]
the scope of the access request, expressed either as an Array or as a space-delimited String.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
quotaProject
string
specifies a project to bill for access charges associated with the request.
static::getCredentials
Obtains the default FetchAuthTokenInterface implementation to use in this environment.
scope
string|string[]
the scope of the access request, expressed either as an Array or as a space-delimited String.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
quotaProject
string|null
specifies a project to bill for access charges associated with the request.
defaultScope
string|string[]|null
The default scope to use if no user-defined scopes exist, expressed either as an Array or as a space-delimited string.
universeDomain
string|null
Specifies a universe domain to use for the calling client library.
logger
null|false| Psr\Log\LoggerInterface
A PSR3 compliant LoggerInterface.
FetchAuthTokenInterface
static::getIdTokenMiddleware
Obtains an AuthTokenMiddleware which will fetch an ID token to use in the Authorization header. The middleware is configured with the default FetchAuthTokenInterface implementation to use in this environment.
If supplied, $targetAudience is used to set the "aud" on the resulting ID token.
targetAudience
string
The audience for the ID token.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
static::getProxyIdTokenMiddleware
Obtains an ProxyAuthTokenMiddleware which will fetch an ID token to use in the Authorization header. The middleware is configured with the default FetchAuthTokenInterface implementation to use in this environment.
If supplied, $targetAudience is used to set the "aud" on the resulting ID token.
targetAudience
string
The audience for the ID token.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
static::getIdTokenCredentials
Obtains the default FetchAuthTokenInterface implementation to use in this environment, configured with a $targetAudience for fetching an ID token.
targetAudience
string
The audience for the ID token.
httpHandler
callable|null
callback which delivers psr7 request
cacheConfig
array|null
configuration for the cache when it's present
cache
Psr\Cache\CacheItemPoolInterface
|null
A cache implementation, may be provided if you have one already available for use.
FetchAuthTokenInterface
static::getDefaultLogger
Returns a StdOutLogger instance
null| Psr\Log\LoggerInterface