Constructor
new TokenHandler(tokenOptions, transporter)
Creates an instance of TokenHandler.
Parameters:
| Name | Type | Description |
|---|---|---|
tokenOptions |
The options for fetching tokens. |
|
transporter |
The transporter to use for making requests. |
Members
inFlightRequest
A promise for an in-flight token request.
token
The cached access token.
tokenExpiresAt
The expiration time of the cached access token.
Methods
(async) getToken(forceRefresh)
Fetches an access token, using a cached one if available and not expired.
Parameters:
| Name | Type | Description |
|---|---|---|
forceRefresh |
If true, forces a new token to be fetched. |
Returns:
| Type | Description |
|---|---|
|
A promise that resolves with the token data. |
hasExpired()
Returns whether the token has completely expired.
Returns:
| Type | Description |
|---|---|
|
true if the token has expired, false otherwise. |
isTokenExpiring()
Checks if the cached token is expired or close to expiring.
Returns:
| Type | Description |
|---|---|
|
True if the token is expiring, false otherwise. |
(async) processCredentials()
Processes the credentials, loading them from a key file if necessary. This method is called before any token request.