Reference documentation and code samples for the Google Auth Library Client class StaticCredentials.
Provides a set of credentials that always returns a pre-issued access token.
No token exchange or HTTP request is ever performed; the supplied token is returned as-is. This is useful for development and testing, or when an access token has already been obtained through some other means and simply needs to be handed to the auth middleware.
use Google\Auth\Credentials\StaticCredentials;
use Google\Auth\Middleware\AuthTokenMiddleware;
$creds = new StaticCredentials('ya29.my-access-token');
$middleware = new AuthTokenMiddleware($creds);
Namespace
Google \ Auth \ CredentialsImplements
Methods
__construct
| Parameters | |
|---|---|
| Name | Description |
accessToken |
string
The pre-issued OAuth2 access token to use. |
expiresIn |
int
[optional] The lifetime of the token in seconds, used to populate its expiration. Defaults to 3600 (one hour). |
fetchAuthToken
Returns the static access token supplied to the constructor.
| Parameter | |
|---|---|
| Name | Description |
httpHandler |
callable|null
Unused; present for interface compatibility. |
| Returns | |
|---|---|
| Type | Description |
array{access_token: string, expires_at: int} |
|
getCacheKey
Returns a cache key derived from the supplied token. Caching a static token has no real benefit, but a stable, token-specific key ensures a shared cache pool never returns another credential's token.
| Returns | |
|---|---|
| Type | Description |
string |
|
getLastReceivedToken
Returns an associative array with the token and expiration time.
| Returns | |
|---|---|
| Type | Description |
array{access_token: string, expires_at: int} |
|