tokenauthentication

This module associates an authentication procedure with a token generation.

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...?)

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

npm install tokenauthentication
var auth = require("tokenauthentication");
 
// Define your authentication function 
// As many arguments as needed 
auth.authenticater = function (usernamepassword) {
    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
}