oauth2-module
v1.0.4
Published
**OAuth2 Module** is a TypeScript module designed to manage authentication processes using the OAuth protocol and handle access tokens. The module provides a convenient interface for initiating authorization, exchanging authorization code for access tok
Downloads
4
Readme
OAuth2 Module
OAuth2 Module is a TypeScript module designed to manage authentication processes using the OAuth protocol and handle access tokens. The module provides a convenient interface for initiating authorization, exchanging authorization code for access tokens, logging out, and checking the token expiration.
Usage
Initialize the Module:
import { OAuthModule, OAuthModuleConfig } from "oauth2-module"; // OAuthModule Configuration const oauthConfig: OAuthModuleConfig = { clientId: "Your Client ID", redirectUri: "Redirect URI", authorizationUrl: "Authorization URL", logoutUrl: "Logout URL", tokenUrl: "Token Exchange URL", scope: ["required scopes"], postLogoutRedirectUri: "Post-Logout Redirect URI", }; const oauthInstance = OAuthModule.getInstance(oauthConfig);
Get Authorization URL:
try { await oauthInstance.getAuthorizationUrl(); } catch (error) { console.error(error); }
Exchange Authorization Code for Token:
try { await oauthInstance.exchangeCodeForToken(); } catch (error) { console.error(error); }
Logout:
try { await oauthInstance.logout(); } catch (error) { console.error(error); }