Socket
Book a DemoInstallSign in
Socket

@onelastjedi/node-jwt

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onelastjedi/node-jwt

Sign and verify JSON Web Tokens in it's simplest form

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

bundle size version downloads

node-jwt

JavaScript library to sign and verify JSON Web Tokens in it's simplest form. Has no dependencies.

Installation

If you use npm, npm install @onelastjedi/node-jwt. You can also download the latest release on GitHub.

Use

import jwt from '@onelastjedi/node-jwt'

const secret = process.env.__SECRET__

const data = {
  exp: 60 * 60 * 24 * 7, // 7 days
  user: { id: 1, name: 'Mary' }
}

jwt.sign(data, secret) // eyJhbGc.....
jwt.verify(token, secret)
/*
  {
    alg: 'HS256',
    typ: 'JWT',
    user: { id: 1, name: 'Mary' },
    iat: ...,
    exp: ...,
    }
*/

API

jwt.sign(body, secret, [alg])

Generated JWT will include an iat (issued at) claim by default. For expiration claim (exp) simply add it to payload. Default signature is HS256.

const exp = 60 * 60 * 24 * 365 // 365 days
const token = jwt.sign({ foo: 'bar', exp: exp }, secret, 'HS384')

jwt.verify(token, secret)

The result of this transformation will be a decrypted body. Possible thrown errors during verification.

const data = jwt.verify(token, secret)

Errors

TokenError: token is expired or signature is invalid.

Algorithms supported

Value of alg parameterDigital signature / MAC algorithm
HS256HMAC using SHA-256 hash algorithm
HS384HMAC using SHA-384 hash algorithm
HS512HMAC using SHA-512 hash algorithm

License

AGPL

Keywords

JWT

FAQs

Package last updated on 31 Oct 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.