$ npm install omantel-jwt
$ npm init -y
{
"clientId":"...",
"secretOrPrivateKey":"...",
"audience":"",
"user":"..."
}
"audience" is not mandatory. You can less empty
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))
$ node index.js
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIuLi4iLCJzdWIiOiIuLi4iLCJhdWQiOiI
iLCJpYXQiOjE2MjYy