Licence
ISC
Version
4.0.1
Deps
3
Size
13 kB
Vulns
0
Weekly
0
Auth utilities class
Main Functionality
This is a collection of utility functions for use in authentication
Main functions
const { jwtUtilAuth, pwdUtilAuth } = require( '@chatpta/auth-util' );
Create jwt
const headerObject = {
alg: "SHA256", // Mendatory acceptable algorithm
...
};
const payloadObject = {
...
};
const jwt = jwtUtilAuth.createSignedJwtFromObject( headerObject, payloadObject, privateKey );
Verify jwt signature returns true or false
const isVerified = jwtUtilAuth.verifyJwtSignature( jwt, publicKey );
Get header and payload object from jwt.
const { header, payload } = jwtUtilAuth.getHeaderPayloadFromJwt( jwt );
Create password hash to save in database
const hash = pwdUtilAuth.createPasswordHashWithRandomSalt( password, secret, algorithm );
Create another password hash based on saved hash to compare.
const hashForLogin = pwdUtilAuth.createPasswordHashBasedOnSavedAlgorithmSalt( passwordForLogin, savedPasswordHash, secret );