quickotp
v1.0.7
Published
Simplified, Quickly OTP Generate, Verify
Downloads
11
Maintainers
Readme
QuickOTP
Simplified, Quickly OTP Generate, Verify on Node.js! OTP, Generated by this module supports Google Authenticator and similar applications.
Support platforms
The quickotp
module works with Node.js v4.x and later version too.
Notice
This module dependency to the qr
module.
qr
module, the operating system-specific additional installation you may need
So, please check this link.
This module use Promise
If you want to use previous callback method, please install previous version as 1.0.6
Installation
$ npm install quickotp
Usage
// If you want to use the TOTP...
const totp = require('quickotp').TOTP;
// If you want to use the HOTP...
const hotp = require('quickotp').HOTP;
let uri = totp.create('key', 'label'); // Create TOTP! (May return the URL with "otpauth" schema)
let uri = hotp.create('key', 'label'); // or Create HOTP! (May return the URL with "otpauth" schema)
// Create OTPAuth URL QRCode (have two ways, but both are the same way.)
// First Way (using TOTP...)
let qrcode = totp.qrcode(uri).then(
(data) => {
// data.uri is return a URL that has been encoded QRCode in Base64. (Content-Type: image/png)
// data.raw is raw png data
console.log(data.uri)
},
(err) => { console.error(err) }
);
// Second Way (using HOTP...)
let qrcode = hotp.qrcode(uri).then(
(data) => {
// data.uri is return a URL that has been encoded QRCode in Base64. (Content-Type: image/png)
// data.raw is raw png data
console.log(data.uri)
},
(err) => { console.error(err) }
);
let verify = totp.verify('key', 'token'); // TOTP Token (OTP Number) Valid check (If valid : return to 'true', invalid : return to false)
let verify = hotp.verify('key', 'token', 'counter') // HOTP Token (OTP Number) Valid check (If valid : return to 'true', invalid : return to false)