tokenauthentication

0.0.3 • Public • Published

TokenAuthentication

This (node.js) module associates an authentication procedure with a token generation. As such, all you have to do is to create a TokenAuthentication object, set your authentication criterias, and then, feel free to ask for token generation any time !

you can also set these settings:

  • Do you want the String-encoded token directly or the Buffer Object it-self ?
  • What length (in bytes) for the generated buffer ?
  • Which encoding do you wanna use for String-encoding ? (hex, utf8...?)

Installation

You can clone this repo, or install it through NPM:

npm install tokenauthentication

How to use ?

var auth = require("tokenauthentication");

// Define your authentication function
// As many arguments as needed
auth.authenticater = function (username, password) {
    return (username === "Tim" && password === "Tom");
};

// Do some of your stuff here...
// ...

// By default, the token return an hex 64 bytes string-encoded token
// But you can ask for the original Buffer Object:
auth.setBufferOnly(true);

// Or also want a longer/smaller buffer ?
// Be careful, it should be a mutiple of 8 !
auth.setTokenSize(16);

// Or, maybe an ascii string-encoded instead of hex ?
// Be sure that the encoding is defined as available
// For that, see the config/default.yaml configuration file
auth.setEncoding("ascii");

// Ask for a token then
// Don't forget to pass needed arguments
var token = auth.getToken("Tim", "Tom");

The returned object from the auth.getToken method is as follow:

{
    "result": true,
    "token": <Your token here>
}

If the authentication is wrong, then:

{
    "result": false,
    "token": null
}

Readme

Keywords

none

Package Sidebar

Install

npm i tokenauthentication

Weekly Downloads

1

Version

0.0.3

License

BSD

Last publish

Collaborators

  • stouf