Creates a new OAuth2Manager instance
OAuth2 configuration options
Clears all stored tokens
Exchanges an authorization code for an access token
The authorization code received from the authorization endpoint
The token data
Gets a valid access token, automatically refreshing if needed
This is the main method to use when you need an access token for API requests. It handles token refresh automatically if the current token is expired or about to expire.
A valid access token
Gets the authorization URL for the authorization code flow
Optionalstate: stringOptional state parameter for CSRF protection
OptionaladditionalParams: Record<string, string>Additional query parameters to include
The authorization URL
Obtains an access token using client credentials flow
The token data
Gets the current token state (for debugging or persistence)
The current token data or null if no tokens are available
Checks if the current access token is valid (exists and not expired)
True if the token is valid, false otherwise
Refreshes the access token using the refresh token
The new token data
Sets the access token directly (for cases where token is obtained externally)
The access token
OptionalrefreshToken: stringOptional refresh token
OptionalexpiresIn: numberOptional expiration time in seconds
Generic OAuth2 token manager supporting multiple grant types and automatic token refresh.
This class provides a standardized way to handle OAuth2 authentication flows including:
Features:
Example