Socket
Book a DemoInstallSign in
Socket

@alexcambose/jwt

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alexcambose/jwt

Simple JWT library for educational purposes only

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

JWT

Simple JWT library for educational purposes only

This module is part of these two Medium publications:

How JWT works — in depth (part 1)

How JWT works — in depth (part 2)

Installation

With npm

npm i -S @alexcambose/jwt
const jwt = require('@alexcambose/jwt');

Usage

Creating a token

const data = { firstName: 'John' };
const secret = 'secretString123';
const token = jwt.sign(data, secret);
// eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTEzMDYzMTksImZpcnN0TmFtZSI6IkpvaG4ifQ.twH5ckfRhGxOIp9Uonq31eFv7xws-xQdtFMOYDg1Wvk

Setting additional options

const data = { firstName: 'John' };
const secret = 'secretString123';
const token = jwt.sign(data, secret, {
  expiration: 60 * 60 // 1 hour
  algorithm: 'HS256',
});
// eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTEzMDYzNTMsImV4cGlyYXRpb24iOjM2MDAsImFsZ29yaXRobSI6IkhTMjU2IiwiZmlyc3ROYW1lIjoiSm9obiJ9.ASNiEo8ZFm-SfSi_wpZUA2mVaCRwtesw6tJ-Fk_ayAk

Verifying a token

const token =
  'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTEzMDYzNTMsImV4cGlyYXRpb24iOjM2MDAsImFsZ29yaXRobSI6IkhTMjU2IiwiZmlyc3ROYW1lIjoiSm9obiJ9.ASNiEo8ZFm-SfSi_wpZUA2mVaCRwtesw6tJ-Fk_ayAk';
const secret = 'secretString123';
const data = jwt.verify(token, secret);
/*
{
  iat: 1591306353,
  expiration: 3600,
  algorithm: 'HS256',
  firstName: 'John'
}
*/

FAQs

Package last updated on 04 Jun 2020

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.