Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@petercraftsmn/auth-util

petercraftsmn70ISC2.2.0

Auth utility functions

auth, utility, cryptology

readme

Auth utilities class

Main Functionality

This is a collection of utility functions for use in authentication

Main functions

Constructor takes default values object

const defaultValues = {
    defaultAlgorithm: 'sha512',
    defaultSecret: 'dev-secret',
    defaultOutputType: 'base64'
};

const authUtil = new AuthUtil(defaultValues);

Creates hash of password -> returns string

  • this string contains $algorithm.hash.salt
createPasswordHash(password, secretKey, algorithm, outputType)

Verify hash -> returns true or false

  • Password: user password
  • passwordHash: hash stored in the database as it is -> created by createPasswordHash() function
  • secretKey: optional key, if different then the key used at initialization
verifyPasswordHash(password, passwordHash, secretKey)

Create JWT -> returns url safe jwt string

  • This string follows jwt specification
createJWT(header, payload, key)

verify JWT signatures -> returns true or false

  • Returns true or false
verifySignatureJWT(jwt, key)

read JWT -> return object containing header, payload, signature

  • Returns object containing { header: {}, payload: {} }
readJWT(jwt)