Creates a new OAuth2Manager instance
OAuth2 configuration options
Use ClearTokens.
Clears all stored tokens
Exchanges an authorization code for an access token
The authorization code received from the authorization endpoint
The token data
Use GetAccessToken.
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
Optionalstate: stringOptionaladditionalParams: Record<string, string>Use GetAuthorizationUrl.
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
Use GetTokenState.
Gets the current token state (for debugging or persistence)
The current token data or null if no tokens are available
Use IsTokenValid.
Checks if the current access token is valid (exists and not expired)
True if the token is valid, false otherwise
Use RefreshAccessToken.
Refreshes the access token using the refresh token
The new token data
OptionalrefreshToken: stringOptionalexpiresIn: numberUse SetTokens.
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