0.1.4 • Published 3 years ago

omantel-jwt v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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
0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago