GCECredentials supports authorization on Google Compute Engine.
It can be used to authorize requests using the AuthTokenMiddleware, but will only succeed if being run on GCE:
use Google\Auth\Credentials\GCECredentials; use Google\Auth\Middleware\AuthTokenMiddleware; use GuzzleHttp\Client; use GuzzleHttp\HandlerStack;
$gce = new GCECredentials(); $middleware = new AuthTokenMiddleware($gce); $stack = HandlerStack::create(); $stack->push($middleware);
$client = new Client([ 'handler' => $stack, 'base_uri' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/', 'auth' => 'google_auth' ]);
$res = $client->get('myproject/taskqueues/myqueue');
Constants |
public Google |
public Google The metadata path of the client ID. |
public Google |
public Google The header whose presence indicates GCE presence. |
public Google The metadata path of the default id token. |
public Google Note: the explicit This allows us to limit the total ping maximum timeout to 1.5 seconds for developer desktop scenarios. |
public Google The metadata IP address on appengine instances. The IP is used instead of the domain 'metadata' to avoid slow responses when not on Compute Engine. |
public Google The metadata path of the project ID. |
public Google The metadata path of the default token. |
public Google The metadata path of the project ID. |
Methods |
public __construct(?Google
|
public fetchAuthToken(?callable $httpHandler = NULL, array $headers = []) Implements FetchAuthTokenInterface#fetchAuthToken. Fetches the auth tokens from the GCE metadata host if it is available. If $httpHandler is not specified a the default HttpHandler is used.
|
public getCacheKey() Returns the Cache Key for the credential token. The format for the cache key is: TokenURI
|
public getClientName(?callable $httpHandler = NULL) Get the client name from GCE metadata. Subsequent calls will return a cached value.
|
public static getClientNameUri( $serviceAccountIdentity = NULL) The full uri for accessing the default service account.
|
public getLastReceivedToken()
|
public getProjectId(?callable $httpHandler = NULL) Fetch the default Project ID from compute engine. Returns null if called outside GCE.
|
public getQuotaProject() Get the quota project used for this API request
|
public static getTokenUri( $serviceAccountIdentity = NULL) The full uri for accessing the default token.
|
public getUniverseDomain(?callable $httpHandler = NULL) : string Fetch the default universe domain from the metadata server.
|
public static onAppEngineFlexible() Determines if this an App Engine Flexible instance, by accessing the GAE_INSTANCE environment variable.
|
public static onGce(?callable $httpHandler = NULL) Determines if this a GCE instance, by accessing the expected metadata host. If $httpHandler is not specified a the default HttpHandler is used.
|
public setIsOnGce( $isOnGce) Set whether or not we've already checked the GCE environment.
|
public signBlob( $stringToSign, $forceOpenSsl = false, $accessToken = NULL) Sign a string using the default service account private key. This implementation uses IAM's signBlob API.
|
Properties |
protected $lastReceivedToken = NULL Result of fetchAuthToken.
|
Methods |
protected getCredType() : string |
Constants |
private Google |
private Google The Linux file which contains the product name. |
private Google The Name of the product expected from the windows registry |
private Google The Windows registry key name for the product name |
private Google The Windows Registry key path to the product name |
Properties |
private $clientName = NULL
|
private $hasCheckedOnGce = false Flag used to ensure that the onGCE test is only done once;.
|
private $iam = NULL
|
private $isOnGce = false Flag that stores the value of the onGCE check.
|
private $projectId = NULL
|
private $quotaProject = NULL
|
private $serviceAccountIdentity = NULL
|
private $targetAudience = NULL
|
private $tokenUri = NULL
|
private ?string $universeDomain
|
Methods |
private static detectResidencyLinux(string $productNameFile) : bool |
private static detectResidencyWindows(string $registryProductKey) : bool |
private getFromMetadata(callable $httpHandler, $uri, array $headers = []) Fetch the value of a GCE metadata server URI.
|
private static getIdTokenUri( $serviceAccountIdentity = NULL) The full uri for accesesing the default identity token.
|
private static getProjectIdUri() The full uri for accessing the default project ID.
|
private static getUniverseDomainUri() The full uri for accessing the default universe domain.
|
Properties |
Methods |
private static detectResidencyLinux(string $productNameFile) : bool |
private static detectResidencyWindows(string $registryProductKey) : bool |
public static getClientNameUri( $serviceAccountIdentity = NULL) The full uri for accessing the default service account.
|
private static getIdTokenUri( $serviceAccountIdentity = NULL) The full uri for accesesing the default identity token.
|
private static getProjectIdUri() The full uri for accessing the default project ID.
|
public static getTokenUri( $serviceAccountIdentity = NULL) The full uri for accessing the default token.
|
private static getUniverseDomainUri() The full uri for accessing the default universe domain.
|
public static onAppEngineFlexible() Determines if this an App Engine Flexible instance, by accessing the GAE_INSTANCE environment variable.
|
public static onGce(?callable $httpHandler = NULL) Determines if this a GCE instance, by accessing the expected metadata host. If $httpHandler is not specified a the default HttpHandler is used.
|