header.payload.signature
const jwt = require("jsonwebtoken")
const token = jwt.sign({ username }, "secret key", { algorithm: "HS256", expiresIn: 300});
If authentication fails:
return res.status(401).end(); // unauthorized
const jwt = require("jsonwebtoken")
// obtain token from body request or cookie
payload = jwt.verify(token, "secret key");
// try/catch the above to return an HTTP error should validation fail
If authentication fails:
return res.status(401).end(); // unauthorized
// https://www.digitalocean.com/community/tutorials/nodejs-jwt-expressjs
const crypto = require('crypto');
crypto.randomBytes(64).toString('hex'); // export this environment variable
Get the secret via process.env.TOKEN_SECRET;
Once generated, the jwt can be passed as a header, or a cookie, or a body parameter.