Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.