omantel-jwt
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

How to easily recover a token (JSON WEB Token)

Install

$ npm install omantel-jwt

Creation package npm

$ npm init -y

Usage

Creation file ./config.json

{
    "clientId":"...",
    "secretOrPrivateKey":"...",
    "audience":"",
    "user":"..."
}

"audience" is not mandatory. You can less empty

Creation file ./index.js

const jwt=require('omantel-jwt')

const config = require('./config.json')

const clientId=config.clientId
const secretOrPrivateKey=config.secretOrPrivateKey
const audience=config.audience
const user=config.user

const lifetime=600
const nowInSeconds = Math.floor(Date.now() / 1000) - 30;
const expInSeconds = nowInSeconds + (lifetime || 300);
const signAlgorithm = "HS256";

const payload = {
  iss: clientId,
  sub: user,
  aud: audience || '',
  iat: nowInSeconds,
  exp: expInSeconds,
};

const options = { algorithm: signAlgorithm}


console.log(jwt.getToken(payload,secretOrPrivateKey,options))

Result in the console

$ node index.js
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIuLi4iLCJzdWIiOiIuLi4iLCJhdWQiOiI
iLCJpYXQiOjE2MjYy

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.4
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.4
    1
  • 0.1.3
    1
  • 0.1.2
    1
  • 0.1.1
    1

Package Sidebar

Install

npm i omantel-jwt

Weekly Downloads

4

Version

0.1.4

License

MIT

Unpacked Size

6.98 kB

Total Files

12

Last publish

Collaborators

  • olivier.mantel.sage