Documentation

ApplicationDefaultCredentials
in package

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');

Table of Contents

Methods

getCredentials()  : CredentialsLoader
Obtains an AuthTokenMiddleware which will fetch an access token to use in the Authorization header. The middleware is configured with the default FetchAuthTokenInterface implementation to use in this environment.
getIdTokenCredentials()  : CredentialsLoader
Obtains the default FetchAuthTokenInterface implementation to use in this environment, configured with a $targetAudience for fetching an ID token.
getIdTokenMiddleware()  : AuthTokenMiddleware
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.
getMiddleware()  : AuthTokenMiddleware
Obtains an AuthTokenMiddleware that uses the default FetchAuthTokenInterface implementation to use in this environment.
getSubscriber()  : AuthTokenSubscriber
Obtains an AuthTokenSubscriber that uses the default FetchAuthTokenInterface implementation to use in this environment.
notFound()  : mixed
onGce()  : mixed

Methods

getCredentials()

Obtains an AuthTokenMiddleware which will fetch an access token to use in the Authorization header. The middleware is configured with the default FetchAuthTokenInterface implementation to use in this environment.

public static getCredentials([string|array<string|int, mixed> $scope = null ][, callable $httpHandler = null ][, array<string|int, mixed> $cacheConfig = null ][, CacheItemPoolInterface $cache = null ][, string $quotaProject = null ][, string|array<string|int, mixed> $defaultScope = null ]) : CredentialsLoader

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

Parameters
$scope : string|array<string|int, mixed> = null

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<string|int, mixed> = null

configuration for the cache when it's present

$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|array<string|int, mixed> = null

The default scope to use if no user-defined scopes exist, expressed either as an Array or as a space-delimited string.

Tags
throws
DomainException

if no implementation can be obtained.

Return values
CredentialsLoader

getIdTokenCredentials()

Obtains the default FetchAuthTokenInterface implementation to use in this environment, configured with a $targetAudience for fetching an ID token.

public static getIdTokenCredentials(string $targetAudience[, callable $httpHandler = null ][, array<string|int, mixed> $cacheConfig = null ][, CacheItemPoolInterface $cache = null ]) : CredentialsLoader
Parameters
$targetAudience : string

The audience for the ID token.

$httpHandler : callable = null

callback which delivers psr7 request

$cacheConfig : array<string|int, mixed> = null

configuration for the cache when it's present

$cache : CacheItemPoolInterface = null

A cache implementation, may be provided if you have one already available for use.

Tags
throws
DomainException

if no implementation can be obtained.

throws
InvalidArgumentException

if JSON "type" key is invalid

Return values
CredentialsLoader

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.

public static getIdTokenMiddleware(string $targetAudience[, callable $httpHandler = null ][, array<string|int, mixed> $cacheConfig = null ][, CacheItemPoolInterface $cache = null ]) : AuthTokenMiddleware

If supplied, $targetAudience is used to set the "aud" on the resulting ID token.

Parameters
$targetAudience : string

The audience for the ID token.

$httpHandler : callable = null

callback which delivers psr7 request

$cacheConfig : array<string|int, mixed> = null

configuration for the cache when it's present

$cache : CacheItemPoolInterface = null

A cache implementation, may be provided if you have one already available for use.

Tags
throws
DomainException

if no implementation can be obtained.

Return values
AuthTokenMiddleware

getMiddleware()

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

public static getMiddleware([mixed $scope = null ][, callable $httpHandler = null ][, array<string|int, mixed> $cacheConfig = null ][, CacheItemPoolInterface $cache = null ][, string $quotaProject = null ]) : AuthTokenMiddleware

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

Parameters
$scope : mixed = null
$httpHandler : callable = null

callback which delivers psr7 request

$cacheConfig : array<string|int, mixed> = null

configuration for the cache when it's present

$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.

Tags
throws
DomainException

if no implementation can be obtained.

Return values
AuthTokenMiddleware

getSubscriber()

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

public static getSubscriber([mixed $scope = null ][, callable $httpHandler = null ][, array<string|int, mixed> $cacheConfig = null ][, CacheItemPoolInterface $cache = null ]) : AuthTokenSubscriber

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

Parameters
$scope : mixed = null
$httpHandler : callable = null

callback which delivers psr7 request

$cacheConfig : array<string|int, mixed> = null

configuration for the cache when it's present

$cache : CacheItemPoolInterface = null

A cache implementation, may be provided if you have one already available for use.

Tags
throws
DomainException

if no implementation can be obtained.

Return values
AuthTokenSubscriber

        
On this page

Search results