Coder Social home page Coder Social logo

jwt-blacklist's Introduction

jwt-blacklist

A module based on node-jsonwebtoken with blacklisting feature.

Install

$ npm install jwt-blacklist

Solution

At early version, we will support to blacklist/revoke jwt in-memory, and synchronize it to file. Incoming version will support to synchronize by redis or memcached.

We use bloom-filter to check whether a jwt is in black list or not. If you haven't heard the term bloom filter, see this

We choose bloomxx for our filters, xxHash has an awesome performance.

To solve the time to live of jwt, we use a set of bloom filters, each bloom filter is responsible for a unit of time (we support hour and day). Whenever all tokens in one bloom filter expire, it will be cleared

Usage

You can use all functions of node-jsonwebtoken in jwt-blacklist

We support two additional functions:

jwtBlacklist.config(config)

Configure the properties of the black list and refresh all bloom filters.

config is an object with following optional fields: maxBlacklistPerUnit, error, unitType, expiresDuration.

We have defaultConfig as following:

  • maxBlacklistPerUnit: maximum token will come per unit of time (default 10000).
  • error: the error rate in double (default 0.001).
  • unitType: the unit type, hour ('h') or day ('d') (default 'd').
  • expiresDuration: the number of unit (default 7 - means 7 days).

Example

const jwt = require('jsonwebtoken');
const jwtBlacklist = require('jwt-blacklist')(jwt);

jwtBlacklist.config({
    maxBlacklistPerUnit: 100000,
    error: 0.00001,
    unitType: 'h',
    expiresDuration: '12'
});

jwtBlacklist.blacklist(token)

Add a jwt token in blacklist.

token is a jwt token

Example

const jwt = require('jsonwebtoken');
const jwtBlacklist = require('jwt-blacklist')(jwt);

let token = jwtBlacklist.sign({
        feeling: 'awesome'
    }, 'secret', {expiresIn: '2h'});

jwtBlacklist.blacklist(token);

jwtBlacklist.verify(token); // throw error

#TODO

  • support other databases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.