Two- / Multi- Factor Authenication (2FA / MFA / OTP) for node.js
Go to file
AJ ONeal c16ce07792 v1.0.0 2015-10-07 12:56:17 -07:00
.gitignore Initial commit 2015-10-07 11:41:39 -07:00
LICENSE Initial commit 2015-10-07 11:41:39 -07:00
README.md v1.0.0 2015-10-07 12:56:17 -07:00
authenticator.js v1.0.0 2015-10-07 12:56:17 -07:00
example.js v1.0.0 2015-10-07 12:56:17 -07:00
package.json v1.0.0 2015-10-07 12:56:17 -07:00

README.md

Node.js Authenticator

Two- and Multi- Factor Authenication (2FA / MFA) for node.js

There are a number of apps that various websites use to give you 6-digit codes to increase security when you log in:

There are many Services that Support MFA, including Google, Microsoft, Facebook, Digital Ocean, for starters.

This module uses notp which implements TOTP (RFC 6238) (the Authenticator standard), which is based on HOTP (RFC 4226) to provide codes that are exactly compatible with all other Authenticator apps and services that use them.

Usage

npm install authenticator --save
'use strict';

var authenticator = require('authenticator');

var formattedKey = authenticator.generateKey();
// "acqo ua72 d3yf a4e5 uorx ztkh j2xl 3wiz"

var formattedToken = authenticator.generateToken(formattedKey);
// "957 124"

authenticator.verifyToken(formattedKey, formattedToken);
// { delta: 0 }

authenticator.verifyToken(formattedKey, '000 000');
// null

QRCode

See https://davidshimjs.github.io/qrcodejs/

'use strict';

var el = document.querySelector('.js-qrcode-canvas');
var link = "otpauth://totp/{{NAME}}?secret={{KEY}}";
var name = "Your Service";
                                              // remove spaces, hyphens, equals, whatever
var key = "acqo ua72 d3yf a4e5 uorx ztkh j2xl 3wiz".replace(/\W/g, '').toLowerCase();

var qr = new QRCode(el, {
  text: link.replace(/{{NAME}}/g, name).replace(/{{KEY}}/g, key)
});

Formatting

All non-alphanumeric characters are ignored, so you could just as well use hyphens or periods or whatever suites your use case.

These are just as valid:

  • "acqo ua72 d3yf a4e5 - uorx ztkh j2xl 3wiz"
  • "98.24.63"

0, 1, 8, and 9 also not used (so that base32). To further avoid confusion with O, o, L, l, I, B, and g you may wish to display lowercase instead of uppercase.

TODO: should this library replace 0 with o, 1 with l (or I?), 8 with b, 9 with g, and so on?

90-second Window

The window is set to +/- 1, meaning each token is valid for a total of 90 seconds (-30 seconds, +0 seconds, and +30 seconds) to account for time drift (which should be very rare for mobile devices) and humans who are handicapped or otherwise struggle with quick fine motor skills (like my grandma).

Why not SpeakEasy?

I took a look at the code and I didn't feel comfortable using it.

For any module related to security I want to see that the code is clean, well-maintained, and that any security-related bugs are addressed.

The author was obviously not well-versed in JavaScript at the time that he wrote it and it hasn't been cleaned up since. Also, the author hasn't been responsive to issues and pull requests.

The notp author has been responsive, but notp doesn't do everything I would like.