Creates a new OAuth2Manager instance
OAuth2 configuration options
Private accessPrivate configPrivate refreshPrivate refreshPrivate tokenExchanges 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
Error if no token is available and cannot be obtained
Gets the authorization URL for the authorization code flow
Optional state: stringOptional state parameter for CSRF protection
Optional additionalParams: 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
Private performRefreshes the access token using the refresh token
The new token data
Error if no refresh token is available
Private requestPrivate Makes a token request to the OAuth2 server
Token request parameters
The token data
Sets the access token directly (for cases where token is obtained externally)
The access token
Optional refreshToken: stringOptional refresh token
Optional expiresIn: 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