CredentialsLoader
in package
implements
FetchAuthTokenInterface, UpdateMetadataInterface
CredentialsLoader contains the behaviour used to locate and find default credentials files on the file system.
Table of Contents
Interfaces
- FetchAuthTokenInterface
- An interface implemented by objects that can fetch auth tokens.
- UpdateMetadataInterface
- Describes a Credentials object which supports updating request metadata (request headers).
Constants
- ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS'
- NON_WINDOWS_WELL_KNOWN_PATH_BASE = '.config'
- TOKEN_CREDENTIAL_URI = 'https://oauth2.googleapis.com/token'
- WELL_KNOWN_PATH = 'gcloud/application_default_credentials.json'
Methods
- fromEnv() : array<string|int, mixed>|null
- Load a JSON key from the path specified in the environment.
- fromWellKnownFile() : array<string|int, mixed>|null
- Load a JSON key from a well known path.
- getUpdateMetadataFunc() : array<string|int, mixed>
- export a callback function which updates runtime metadata.
- makeCredentials() : ServiceAccountCredentials|UserRefreshCredentials
- Create a new Credentials instance.
- makeHttpClient() : Client
- Create an authorized HTTP Client from an instance of FetchAuthTokenInterface.
- makeInsecureCredentials() : InsecureCredentials
- Create a new instance of InsecureCredentials.
- updateMetadata() : array<string|int, mixed>
- Updates metadata with the authorization token.
- getGuzzleMajorVersion() : int
- Returns the currently available major Guzzle version.
- isOnWindows() : bool
- unableToReadEnv() : string
Constants
ENV_VAR
public
mixed
ENV_VAR
= 'GOOGLE_APPLICATION_CREDENTIALS'
NON_WINDOWS_WELL_KNOWN_PATH_BASE
public
mixed
NON_WINDOWS_WELL_KNOWN_PATH_BASE
= '.config'
TOKEN_CREDENTIAL_URI
public
mixed
TOKEN_CREDENTIAL_URI
= 'https://oauth2.googleapis.com/token'
WELL_KNOWN_PATH
public
mixed
WELL_KNOWN_PATH
= 'gcloud/application_default_credentials.json'
Methods
fromEnv()
Load a JSON key from the path specified in the environment.
public
static fromEnv() : array<string|int, mixed>|null
Load a JSON key from the path specified in the environment variable GOOGLE_APPLICATION_CREDENTIALS. Return null if GOOGLE_APPLICATION_CREDENTIALS is not specified.
Return values
array<string|int, mixed>|null —JSON key | null
fromWellKnownFile()
Load a JSON key from a well known path.
public
static fromWellKnownFile() : array<string|int, mixed>|null
The well known path is OS dependent:
- windows: %APPDATA%/gcloud/application_default_credentials.json
- others: $HOME/.config/gcloud/application_default_credentials.json
If the file does not exist, this returns null.
Return values
array<string|int, mixed>|null —JSON key | null
getUpdateMetadataFunc()
export a callback function which updates runtime metadata.
public
getUpdateMetadataFunc() : array<string|int, mixed>
Return values
array<string|int, mixed> —updateMetadata function
makeCredentials()
Create a new Credentials instance.
public
static makeCredentials(string|array<string|int, mixed> $scope, array<string|int, mixed> $jsonKey[, string|array<string|int, mixed> $defaultScope = null ]) : ServiceAccountCredentials|UserRefreshCredentials
Parameters
- $scope : string|array<string|int, mixed>
-
the scope of the access request, expressed either as an Array or as a space-delimited String.
- $jsonKey : array<string|int, mixed>
-
the JSON credentials.
- $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.
Return values
ServiceAccountCredentials|UserRefreshCredentialsmakeHttpClient()
Create an authorized HTTP Client from an instance of FetchAuthTokenInterface.
public
static makeHttpClient(FetchAuthTokenInterface $fetcher[, array<string|int, mixed> $httpClientOptions = [] ][, callable $httpHandler = null ][, callable $tokenCallback = null ]) : Client
Parameters
- $fetcher : FetchAuthTokenInterface
-
is used to fetch the auth token
- $httpClientOptions : array<string|int, mixed> = []
-
(optional) Array of request options to apply.
- $httpHandler : callable = null
-
(optional) http client to fetch the token.
- $tokenCallback : callable = null
-
(optional) function to be called when a new token is fetched.
Return values
ClientmakeInsecureCredentials()
Create a new instance of InsecureCredentials.
public
static makeInsecureCredentials() : InsecureCredentials
Return values
InsecureCredentialsupdateMetadata()
Updates metadata with the authorization token.
public
updateMetadata(array<string|int, mixed> $metadata[, string $authUri = null ][, callable $httpHandler = null ]) : array<string|int, mixed>
Parameters
- $metadata : array<string|int, mixed>
-
metadata hashmap
- $authUri : string = null
-
optional auth uri
- $httpHandler : callable = null
-
callback which delivers psr7 request
Return values
array<string|int, mixed> —updated metadata hashmap
getGuzzleMajorVersion()
Returns the currently available major Guzzle version.
private
static getGuzzleMajorVersion() : int
Return values
intisOnWindows()
private
static isOnWindows() : bool
Return values
boolunableToReadEnv()
private
static unableToReadEnv(string $cause) : string
Parameters
- $cause : string