@insomnia-labs/fan-passport-auth
v2.0.7
Published
Simple library to handle encryption and decryption of volt tokens and sharing auth to ICC fan passport application
Downloads
74
Readme
ICC Fan Passport Auth
The fan-passport-auth
library provides a class, ICCPassportAuth
, that provides a set of utilities for managing ICC tokens and authentication for the fan passport application. It facilitates secure communication between the main ICC applications and the ICC Fan Passport application by handling user authentication tokens. It exposes methods to
encryption users access token, decrypt the access token, and revoke the users access token.
Installation
To install the package, run the following command in your project directory:
npm i @insomnia-labs/fan-passport-auth
Usage
Initializing the Authentication Class
Import the ICCPassportAuth
class from the package and initialize it with the desired environment.
import { ICCPassportAuth } from 'fan-passport-auth';
// Initialize with production environment
const auth = new ICCPassportAuth("production");
Encrypting a Token
Use the encryptToken
method to encrypt a user's volt token. This token can then be included in URLs for redirecting users to the fan passport application.
async function encryptUserToken() {
const encryptedToken = await auth.encryptToken({
token: "userVoltTokenHere",
name: "Samuel Olamide",
email: "[email protected]",
});
console.log("Encrypted Token:", encryptedToken);
}
encryptUserToken();
Validating an Encrypted Token
After encrypting a token, use validateToken
to validate the encrypted token and optionally create a user instance on the application.
async function validateUserToken(encryptedToken) {
const accessToken = await auth.validateToken(encryptedToken);
console.log("Access Token:", accessToken);
}
Revoking an Access Token
To log a user out and invalidate their session, use the revokeAccessToken
method.
async function revokeUserAccessToken(token) {
const response = await auth.revokeAccessToken(token);
console.log("Revoke Response:", response); // { statusCode: 200, message: 'Logged out successfully.' }
}
Support
For issues or feature requests, please reach out to the insomnia team.