-
Notifications
You must be signed in to change notification settings - Fork 4
JSON WEB TOKEN
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA
npm install jsonwebtoken
In our application once the user is logged in, each subsequent request to a page will internally call the JWT, allowing the user to access routes, services, and resources that are permitted with that token. Single Sign On is a feature that widely uses JWT nowadays, because of its small overhead and its ability to be easily used across different domains.
We are using secretOrPrivateKey a string, buffer, or object containing either the secret for HMAC algorithms or the PEM encoded private key for RSA and ECD We are setting timeout of secretOrPrivateKey parameter to 1 hour.
/users/login To set the secretOrPrivateKey and timeout to 60 minutes
console.log(user);
var token = jwt.sign({ data: user }, 'mysecretkey', { expiresIn: tokenExpireTime });
user.password = '';
res.status(200);
return res.json({
success: true,
message: 'Login successful',
token: token,
data: user
});
No Database Involved
More information can be obtained from https://www.npmjs.com/package/jsonwebtoken