UserRefreshCredentials
extends CredentialsLoader
in package
implements
GetQuotaProjectInterface
Authenticates requests using User Refresh credentials.
This class allows authorizing requests from user refresh tokens.
This the end of the result of a 3LO flow. E.g, the end result of 'gcloud auth login' saves a file with these contents in well known location
Tags
Table of Contents
Interfaces
- GetQuotaProjectInterface
- An interface implemented by objects that can get quota projects.
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'
Properties
- $auth : OAuth2
- The OAuth2 instance used to conduct authorization.
- $quotaProject : mixed
- The quota project associated with the JSON credentials
Methods
- __construct() : mixed
- Create a new UserRefreshCredentials.
- fetchAuthToken() : array<string|int, mixed>
- Fetches the auth tokens based on the current state.
- 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.
- getCacheKey() : string
- Obtains a key that can used to cache the results of #fetchAuthToken.
- getLastReceivedToken() : array<string|int, mixed>
- Returns an associative array with the token and expiration time.
- getQuotaProject() : string|null
- Get the quota project used for this API request
- 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'
Properties
$auth
The OAuth2 instance used to conduct authorization.
protected
OAuth2
$auth
$quotaProject
The quota project associated with the JSON credentials
protected
mixed
$quotaProject
Methods
__construct()
Create a new UserRefreshCredentials.
public
__construct(string|array<string|int, mixed> $scope, string|array<string|int, mixed> $jsonKey) : mixed
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 : string|array<string|int, mixed>
-
JSON credential file path or JSON credentials as an associative array
fetchAuthToken()
Fetches the auth tokens based on the current state.
public
fetchAuthToken([callable $httpHandler = null ]) : array<string|int, mixed>
Parameters
- $httpHandler : callable = null
Return values
array<string|int, mixed> —A set of auth related metadata, containing the following keys:
- access_token (string)
- expires_in (int)
- scope (string)
- token_type (string)
- id_token (string)
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
getCacheKey()
Obtains a key that can used to cache the results of #fetchAuthToken.
public
getCacheKey() : string
Return values
stringgetLastReceivedToken()
Returns an associative array with the token and expiration time.
public
getLastReceivedToken() : array<string|int, mixed>
Return values
array<string|int, mixed>getQuotaProject()
Get the quota project used for this API request
public
getQuotaProject() : string|null
Return values
string|nullgetUpdateMetadataFunc()
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