Skip to content

About

A JWT authentication / authorization helper library

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

auth-tools

Build StatusDependency Status

A simple JWT encoding / encryption helper library

Installing

$ npm i @compit/auth-tools

Usage

Simple jwt token

const { encodeToken, decodeToken } = require('@compit/auth-tools');

const dataToEncode = { someData: 123 };
const jwtSecret = 'Some JWT Secret';

const token = await encodeToken({ 
  payload: { someData: 123 }, 
  expiresIn: '7d', 
  jwtSecret
});

const decodedToken = await decodeToken({ 
  token, // Same token we just encoded
  jwtSecret
});

console.log(decodedToken); // { someData: 123 }

Using encryption

const { encodeToken, decodeToken } = require('@compit/auth-tools');

const dataToEncode = { someData: 123 };
const shaPassword = 'Some encryption Password';
const jwtSecret = 'Some JWT Secret';

const token = await encodeToken({ 
  payload: { someData: 123 }, 
  expiresIn: '7d', 
  jwtSecret, 
  
  // Add these to have to token encrypt the data (AES SHA 256)
  isToEncrypt: true, 
  shaPassword
});

const decodedToken = await decodeToken({ 
  token, // Same token we just encoded
  jwtSecret, 

  // Add these to have to token decrypt the data (AES SHA 256)
  isToDecrypt: true, 
  shaPassword 
});

console.log(decodedToken); // { someData: 123 }

About

A JWT authentication / authorization helper library

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages