@onspark/auth-util
v0.0.1
Published
Auth utility functions
Downloads
81
Readme
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 );