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.
To install the package, run the following command in your project directory:
npm i @insomnia-labs/fan-passport-auth
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");
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: "samuel.olamide@domain.com",
});
console.log("Encrypted Token:", encryptedToken);
}
encryptUserToken();
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);
}
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.' }
}
For issues or feature requests, please reach out to the insomnia team.