ApplicationDefaultCredentials
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
No description
Obtains an AuthTokenMiddleware that uses the default FetchAuthTokenInterface implementation to use in this environment.
Obtains the default FetchAuthTokenInterface implementation to use in this environment.
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.
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.
Obtains the default FetchAuthTokenInterface implementation to use in this environment, configured with a $targetAudience for fetching an ID token.
Details
static AuthTokenSubscriber
getSubscriber(string|string[] $scope = null, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null)
deprecated
deprecated
No description
static AuthTokenMiddleware
getMiddleware(string|string[] $scope = null, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null, string $quotaProject = 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.
static FetchAuthTokenInterface
getCredentials(string|string[] $scope = null, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null, string|null $quotaProject = null, string|string[]|null $defaultScope = null, string|null $universeDomain = null)
Obtains the default FetchAuthTokenInterface implementation to use in this environment.
static AuthTokenMiddleware
getIdTokenMiddleware(string $targetAudience, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null)
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.
static ProxyAuthTokenMiddleware
getProxyIdTokenMiddleware(string $targetAudience, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null)
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.
static FetchAuthTokenInterface
getIdTokenCredentials(string $targetAudience, callable|null $httpHandler = null, array|null $cacheConfig = null, CacheItemPoolInterface|null $cache = null)
Obtains the default FetchAuthTokenInterface implementation to use in this environment, configured with a $targetAudience for fetching an ID token.