Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@dsninjas/jwt
Advanced tools
Jwt Helpers for node.js projects
This module makes it easy to issue and verify tokens in node.js applications.
npm
:npm install @dsninjas/jwt
yarn
:yarn add @dsninjas/jwt
The constructor helps you configure the jwt helper class.
const secret = 'qwerty';
const audience = 'example.com';
const issuer = 'example.com';
const jwtHelper = new JwtHelper(secret, audience, issuer);
The constructor takes the following options:
This method helps you to generate the token. It responses with a promise if you don't secify a callback, else returns the result with in callback.
With promise:
const secret = 'qwerty';
const audience = 'example.com';
const issuer = 'example.com';
const expireIn = '7d';
const jwtHelper = new JwtHelper(secret, audience, issuer);
const message = 'Hello';
const result = jwtHelper.issue({ message }, expireIn);
result.then((result) => {
console.log(result);
}.catch((err) => {
console.log(err);
});
With callback:
const secret = 'qwerty';
const audience = 'example.com';
const issuer = 'example.com';
const expireIn = '7d';
const jwtHelper = new JwtHelper(secret, audience, issuer);
const message = 'Hello';
jwtHelper.issue({ message }, expireIn,'jwt-auth-token',(err,result) => {
if (err) {
console.log(err);
}
console.log(result);
}
Sample response:
{
uuid: '4c71ae9d-755a-4d18-9eef-4a600bfb0c14',
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiNmMkNU0iLCJpYXQiOjE1MTYxOTU3NTQsImV4cCI6MTUxNjgwMDU1NCwiYXVkIjoiaHR0cDovL251bi52Yy9zaW13aSIsImlzcyI6Imh0dHA6Ly9udW4udmMvc2ltd2kiLCJzdWIiOiJqd3QtYXV0aC10b2tlbiIsImp0aSI6IjRjNzFhZTlkLTc1NWEtNGQxOC05ZWVmLTRhNjAwYmZiMGMxNCJ9.khIFuxlb4mF8iZnRc_qbXfzjbzd0XNY7CKauSCcKB6U'
}
This method helps you to validate the token. It responses with a promise if you don't secify a callback, else returns the result with in callback.
With promise:
const secret = 'qwerty';
const audience = 'example.com';
const issuer = 'example.com';
const expireIn = '7d';
const jwtHelper = new JwtHelper(secret, audience, issuer);
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiNmMkNU0iLCJpYXQiOjE1MTYxOTU3NTQsImV4cCI6MTUxNjgwMDU1NCwiYXVkIjoiaHR0cDovL251bi52Yy9zaW13aSIsImlzcyI6Imh0dHA6Ly9udW4udmMvc2ltd2kiLCJzdWIiOiJqd3QtYXV0aC10b2tlbiIsImp0aSI6IjRjNzFhZTlkLTc1NWEtNGQxOC05ZWVmLTRhNjAwYmZiMGMxNCJ9.khIFuxlb4mF8iZnRc_qbXfzjbzd0XNY7CKauSCcKB6U';
const result = jwtHelper.verify(token, expireIn);
result.then((result) => {
console.log(result);
}.catch((err) => {
console.log(err);
});
With callback:
const secret = 'qwerty';
const audience = 'example.com';
const issuer = 'example.com';
const expireIn = '7d';
const jwtHelper = new JwtHelper(secret, audience, issuer);
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXNzYWdlIjoiNmMkNU0iLCJpYXQiOjE1MTYxOTU3NTQsImV4cCI6MTUxNjgwMDU1NCwiYXVkIjoiaHR0cDovL251bi52Yy9zaW13aSIsImlzcyI6Imh0dHA6Ly9udW4udmMvc2ltd2kiLCJzdWIiOiJqd3QtYXV0aC10b2tlbiIsImp0aSI6IjRjNzFhZTlkLTc1NWEtNGQxOC05ZWVmLTRhNjAwYmZiMGMxNCJ9.khIFuxlb4mF8iZnRc_qbXfzjbzd0XNY7CKauSCcKB6U';
const result = jwtHelper.verify(token, expireIn,'jwt-auth-token',(err,result) => {
if (err) {
console.log(err);
}
console.log(result);
}
Sample response:
{
message: '6c$5M',
iat: 1516195754,
exp: 1516800554,
aud: 'http://nun.vc/simwi',
iss: 'http://nun.vc/simwi',
sub: 'jwt-auth-token',
jti: '4c71ae9d-755a-4d18-9eef-4a600bfb0c14'
}
FAQs
Jwt Helper for node.js projects
The npm package @dsninjas/jwt receives a total of 0 weekly downloads. As such, @dsninjas/jwt popularity was classified as not popular.
We found that @dsninjas/jwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.