1.0.6 • Published 7 years ago

jwt-tokens v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

JWT-Tokens

The jwt-tokens library exported as Node.js modules.

Docs

Generates a JWT token using a private key and also validates a JWT token using a public key Simplifies the JWT validation and creation process.

Installation

npm install jwt-tokens

Data Structure

Create an Object with the information to be encrypted

var userInfo = {company:"wavecoders", email:"someone@somwhere.com", name:"unknow user name"};

Init

var JWTTokens = require('jwt-tokens');

Create JWT Token

Successful Token with Old Expiry date To create an expiry date for the token, the following structured object is require:

{ seconds:0, minutes:0, hours:0, days:0, days30:0, years:0 }

You may use any number of params you wish to include. In the example below we only use days. If you omit the expiry date, the token will expire in 30 days by default.

var token1 = JWTTokens.createJWT(userInfo, {days:15});

Failed Token with Old Expiry date

var token2 = JWTTokens.createJWT(userInfo, {days:-15});

Validate a JWT Token

On client side your application will pass the user information (Data Structure) and License Key:

Successful

try{
    JWTTokens.validateJWT(token1);
    console.log('valid token');
}catch(err){
    console.log('faild validation');
}

success: valid token

Failed Token

try{
    JWTTokens.validateJWT(token2);
    console.log('valid token');
}catch(err){
    console.log('faild validation');
}

error: faild validation

Support

Tested in Chrome 53-54, Firefox 48-49, IE 11, Edge 14, Safari 9-10, Node.js 6-7, & PhantomJS 2.1.1. Automated test runs are available.

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago