GithubHelp home page GithubHelp logo

jwt-service's Introduction

jwt-service

A simple wrapper for a simpler JWT surface API

Build status Coverage Status NPM version Dependency Status devDependency Status Dependency Status Package Quality Code Climate

This wrapper is directly usable with Knifecycle.

API

initJWT(services) ⇒ Promise.<Object>

Instantiate the JWT service

Kind: global function
Returns: Promise.<Object> - A promise of the jwt service

Param Type Description
services Object The services to inject
services.JWT function The JWT service configuration object
[services.log] function A logging function
[services.time] function A function returning the current timestamp

Example

import initJWTService from 'jwt-service';

const jwt = await initJWTService({
  JWT: {
    secret: 'secret',
    duration: '2d',
    tolerance: '2h',
    algorithms: ['HS256'],
  },
  log: console.log.bind(console),
  time: Date.now.bind(Date),
});

const token = await jwt.sign({ my: 'payload' });

initJWT~sign(payload, [algorithm]) ⇒ Promise.<String>

Sign the given payload

Kind: inner method of initJWT
Returns: Promise.<String> - A promise to be resolved with the signed token.

Param Type Description
payload Object The payload to sign
[algorithm] String The signing algorithm

Example

const token = await jwt.sign({ my: 'payload' });

initJWT~verify([token]) ⇒ Promise.<Object>

Verify and decode the given token

Kind: inner method of initJWT
Returns: Promise.<Object> - A promise to be resolved with the token payload.

Param Type Description
[token] String The token to decode

Example

const payload = await jwt.decode('my.jwt.token');

Authors

License

MIT

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.