Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@coolgk/jwt

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coolgk/jwt

a simple jwt token class

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

@coolgk/jwt

a javascript / typescript module

npm install @coolgk/jwt

a simple jwt token class

Report bugs here: https://github.com/coolgk/node-utils/issues

Examples

import { Jwt } from '@coolgk/jwt';
// OR
// const { Jwt } = require('@coolgk/jwt');

const jwt = new Jwt({secret: 'abc'});

const string = 'http://example.com/a/b/c?a=1';

const token = jwt.generate(string);

console.log(
    jwt.verify(token), // { exp: 0, iat: 1512307492763, rng: 0.503008668963175, data: 'http://example.com/a/b/c?a=1' }
    jwt.verify(token+'1') // false
);

const token2 = jwt.generate(string, 200);

console.log(
    jwt.verify(token2), // { exp: 1512307493026, iat: 1512307492826, rng: 0.5832258275608753, data: 'http://example.com/a/b/c?a=1' }
    jwt.verify(token+'1') // false
);

setTimeout(() => {
    console.log(jwt.verify(token2)); // false
}, 250);

Jwt

Kind: global class

new Jwt(options)

ParamTypeDescription
optionsobject
options.secretstringfor encryption

jwt.generate(data, [expiry]) ⇒ string

Kind: instance method of Jwt

ParamTypeDefaultDescription
data*any data can be JSON.stringify'ed
[expiry]number0in milliseconds 0 = never expire

jwt.verify(token) ⇒ boolean | object

Kind: instance method of Jwt
Returns: boolean | object - - false or the payload of the token

ParamTypeDescription
tokenstringtoken to verify

Keywords

FAQs

Package last updated on 08 Aug 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc