This module associates an authentication procedure with a token generation.
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 neededreturn 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:authsetBufferOnlytrue;// Or also want a longer/smaller buffer ?// Be careful, it should be a mutiple of 8 !authsetTokenSize16;// 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 fileauthsetEncoding"ascii";// Ask for a token then// Don't forget to pass needed argumentsvar token = authgetToken"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