0.1.2 • Published 8 years ago

@webgap/token v0.1.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 years ago

WebGAP Token

Build Status Test Coverage Code Climate Dependency Status

NPM version NPM downloads

README

WebGAP Tokenizer module. Handles JWT encoding / decoding features. Handles authentication tokens creation.

Dependencies

Loads default configuration using @webgap/configuration. Handles Dates using moment. Handles JWT using jwt-simple. Handles Authentication Token creation using hat.

API

Installation

npm install @webgap/token --save

Usage

// jwt tokens
var HS512Algorithm = require('../index').JsonWebToken.HS512Algorithm;
var RS256Algorithm = require('../index').JsonWebToken.RS256Algorithm;

var HSAlgorithm = new HS512Algorithm({
      secret: 'a_secret_key'
    });
var HSDataEncoded = HSAlgorithm.encode('data');
HSAlgorithm.decode(HSDataEncoded); // decodes the data
HSAlgorithm.isValid(HSDataEncoded); // true or false

var RSAlgorithm = new RS256Algorithm({
      privateKeyPath: __dirname + '/keys/token-private.ppk',
      publicKeyPath: __dirname + '/keys/token-public.key'
    });
var RSDataEncoded = RSAlgorithm.encode({data: { field: 0}});
RSAlgorithm.decode(RSDataEncoded); // decodes the data
RSAlgorithm.isValid(RSDataEncoded); // true or false

// authentication tokens
var HatAuthAlgorithm = require('../index').AuthToken.HatAlgorithm;
var hatAlgorithm = new HatAuthAlgorithm();
hatAlgorithm.encode(); // returns a token like: 92d522476573347b7fd9ebcfc02f3a501bb6db82c745bc92de9553d5ca3b1a41

Options

// common options  
var options = {
  host: 'localhost',
  validityThreshold: 100
};

// HS algorithm uses a secret key
options.secret: 'a_secret_key'

// RS algorithm uses pub / private keys
options.privateKeyPath: '/keys/token-private.ppk',
options.publicKeyPath: '/keys/token-public.key'

If no 'options' is provided, the module will try to load default configurations from @webgap/configuration module.

Default configurations for this module are as follows:

SERVER.HOST - the hostname
GENERAL.TOKEN.VALIDITY_TIME - the jwt token validity in milliseconds

License

Apache License, Version 2.0

0.1.2

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago