Compare commits

...

26 Commits

Author SHA1 Message Date
AJ ONeal
0c021be7a3 v1.1.5 - update cli package 2018-05-29 14:26:28 -06:00
8826eda195 Merge branch 'master' of rajivshah3/node-authenticator.js into master 2018-05-29 20:24:10 +00:00
Rajiv Shah
f67283c91c
Upgrade authenticator-cli to 1.0.5 2018-05-26 17:49:43 -04:00
AJ ONeal
406e7b118c v1.1.4 2018-03-28 00:30:33 -06:00
fad69a2ba9 Update 'README.md' 2017-11-20 16:36:53 +00:00
AJ ONeal
32196b4a67 udpate urls 2017-09-22 16:55:21 -06:00
AJ ONeal
b912f75a53 auto-update banner 2016-12-30 02:38:02 -07:00
AJ ONeal
7884491693 auto-update ad 2016-12-30 00:52:09 -07:00
AJ ONeal
71599a554d Update README.md 2016-11-25 10:22:04 -07:00
AJ ONeal
d404e5406e Update README.md 2016-11-01 18:29:31 -06:00
AJ ONeal
776b8beb8a v1.1.2 2016-01-02 01:25:50 -08:00
AJ ONeal
cccf7dba05 make executable 2016-01-02 01:25:46 -08:00
AJ ONeal
bf5c24af58 v1.1.1 2016-01-02 01:24:28 -08:00
AJ ONeal
5ba2cdddf2 add bin 2016-01-02 01:24:24 -08:00
AJ ONeal
0178e8b89d Update README.md 2016-01-02 01:15:06 -08:00
AJ ONeal
524283161e Update README.md 2016-01-02 01:13:22 -08:00
AJ ONeal
b3fd9ad34a bump 2015-11-03 00:16:46 -08:00
AJ ONeal
48d1dcad7f document generateTotpUri 2015-11-03 00:16:18 -08:00
AJ ONeal
eb55534c48 add generateTotpUri() 2015-11-03 00:02:32 -08:00
AJ ONeal
461202f0ed Update README.md 2015-10-24 11:38:31 -07:00
AJ ONeal
8745e27827 Update README.md 2015-10-24 11:37:14 -07:00
AJ ONeal
b313639df5 Update README.md 2015-10-23 12:06:45 -07:00
AJ ONeal
93daa0ab8d Update README.md 2015-10-23 01:15:32 -07:00
AJ ONeal
7e2c686f37 Update README.md 2015-10-22 19:15:13 -07:00
AJ ONeal
616c04fa6d Update README.md 2015-10-22 19:12:52 -07:00
AJ ONeal
011c4b9cdd Update README.md 2015-10-22 19:07:47 -07:00
4 changed files with 85 additions and 28 deletions

View File

@ -1,13 +1,17 @@
Node.js Authenticator
=====================
| Sponsored by [ppl](https://ppl.family)
Two- and Multi- Factor Authenication (2FA / MFA) for node.js
![](https://blog.authy.com/assets/posts/authenticator.png)
There are a number of apps that various websites use to give you 6-digit codes to increase security when you log in:
* Authy [iPhone](https://itunes.apple.com/us/app/authy/id494168017?mt=8) • [Android](https://play.google.com/store/apps/details?id=com.authy.authy&hl=en) • [Chrome](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en) • [Linux](https://www.authy.com/personal/) • [OS X](https://www.authy.com/personal/) • [BlackBerry](https://appworld.blackberry.com/webstore/content/38831914/?countrycode=US&lang=en)
* Google Authenticator [iPhone](https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8) [Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en)
* Microsoft Authenticator [Windows Phone](https://www.microsoft.com/en-us/store/apps/authenticator/9wzdncrfj3rj) [Android](https://play.google.com/store/apps/details?id=com.microsoft.msa.authenticator)
* Authy (shown above) [iPhone](https://itunes.apple.com/us/app/authy/id494168017?mt=8) | [Android](https://play.google.com/store/apps/details?id=com.authy.authy&hl=en) | [Chrome](https://chrome.google.com/webstore/detail/authy/gaedmjdfmmahhbjefcbgaolhhanlaolb?hl=en) | [Linux](https://www.authy.com/personal/) | [OS X](https://www.authy.com/personal/) | [BlackBerry](https://appworld.blackberry.com/webstore/content/38831914/?countrycode=US&lang=en)
* Google Authenticator [iPhone](https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8) | [Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en)
* Microsoft Authenticator [Windows Phone](https://www.microsoft.com/en-us/store/apps/authenticator/9wzdncrfj3rj) | [Android](https://play.google.com/store/apps/details?id=com.microsoft.msa.authenticator)
* GAuth [FxOS](https://marketplace.firefox.com/app/gauth/)
There are many [Services that Support MFA](http://lifehacker.com/5938565/heres-everywhere-you-should-enable-two-factor-authentication-right-now),
@ -17,13 +21,31 @@ This module uses [`notp`](https://github.com/guyht/notp) which implements `TOTP`
(the *Authenticator* standard), which is based on `HOTP` [(RFC 4226)](https://www.ietf.org/rfc/rfc4226.txt)
to provide codes that are exactly compatible with all other *Authenticator* apps and services that use them.
Usage
Browser & Commandline Authenticator
---------------------
You may also be interested in
* [Browser Authenticator](https://git.coolaj86.com/coolaj86/browser-authenticator) over at <https://git.coolaj86.com/coolaj86/browser-authenticator>
* [Commandline Authenticator](https://git.coolaj86.com/coolaj86/authenticator-cli) over at <https://git.coolaj86.com/coolaj86/authenticator-cli>
Install
=====
**node.js api**
```bash
npm install authenticator --save
```
**command line**
```bash
npm install authenticator-cli --global
```
Usage
=====
**node.js api**
```javascript
'use strict';
@ -40,29 +62,51 @@ authenticator.verifyToken(formattedKey, formattedToken);
authenticator.verifyToken(formattedKey, '000 000');
// null
authenticator.generateTotpUri(formattedKey, "john.doe@email.com", "ACME Co", 'SHA1', 6, 30);
//
// otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30
```
### API
**command line**
```
# see help
authenticator --help
### generateKey()
# generate a key and display qr code
authenticator --qr
```
generates a 32-character (160-bit) base32 key
API
---
### generateToken(formattedKey)
```javascript
generateKey() // generates a 32-character (160-bit) base32 key
generates a 6-digit (20-bit) decimal time-based token
generateToken(formattedKey) // generates a 6-digit (20-bit) decimal time-based token
### verifyToken(formattedKey, formattedToken)
verifyToken(formattedKey, formattedToken) // validates a time-based token within a +/- 30 second (90 seconds) window
// returns `null` on failure or an object such as `{ delta: 0 }` on success
validates a time-based token within a +/- 30 second (90 seconds) window
// generates an `OTPAUTH://` scheme URI for QR Code generation.
generateTotpUri(formattedKey, accountName, issuer, algorithm, digits, period)
```
returns `null` on failure or an object such as `{ delta: 0 }` on success
**OTPAuth Scheme**
* <https://github.com/google/google-authenticator/wiki/Key-Uri-Format>
* `otpauth://totp/<<ISSUER>>:<<ACCOUNT_NAME>>?secret=<<BASE32_KEY>>&issuer=<<ISSUER>>`
* `otpauth://totp/<<ISSUER>>:<<ACCOUNT_NAME>>?secret=<<BASE32_KEY>>&issuer=<<ISSUER>>&algorithm=<<ALGO>>&digits=<<INT>>&period=<<SECONDS>>`
Note that `ISSUER` is specified twice for backwards / forwards compatibility.
QR Code
-------
See <https://davidshimjs.github.io/qrcodejs/> and <https://github.com/soldair/node-qrcode>.
![](http://cdn9.howtogeek.com/wp-content/uploads/2014/10/sshot-7-22.png)
Example use with `qrcode.js` in the browser:
```javascript
@ -108,13 +152,4 @@ and humans who are handicapped or otherwise struggle with quick fine motor skill
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.
It doesn't use native node crypto and there are open security issues which have been left unaddressed.

View File

@ -57,3 +57,15 @@ function verifyGoogleAuthToken(key, token) {
module.exports.generateKey = generateGoogleAuthKey;
module.exports.generateToken = generateGoogleAuthToken;
module.exports.verifyToken = verifyGoogleAuthToken;
module.exports.generateTotpUri = function (secret, accountName, issuer, algo, digits, period) {
// Full OTPAUTH URI spec as explained at
// https://github.com/google/google-authenticator/wiki/Key-Uri-Format
return 'otpauth://totp/'
+ encodeURI(issuer || '') + ':' + encodeURI(accountName || '')
+ '?secret=' + secret.replace(/[\s\.\_\-]+/g, '').toUpperCase()
+ '&issuer=' + encodeURIComponent(issuer || '')
+ '&algorithm=' + (algo || 'SHA1')
+ '&digits=' + (digits || 6)
+ '&period=' + (period || 30)
;
};

4
bin/authenticator.js Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env node
'use strict';
module.exports = require('authenticator-cli/bin/authenticator');

View File

@ -1,14 +1,17 @@
{
"name": "authenticator",
"version": "1.0.1",
"version": "1.1.5",
"description": "Two- / Multi- Factor Authenication (2FA / MFA) for node.js",
"main": "authenticator.js",
"scripts": {
"test": "node example.js"
},
"bin": {
"authenticator": "bin/authenticator.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Daplie/node-authenticator.git"
"url": "git+https://git.coolaj86.com/coolaj86/node-authenticator.js.git"
},
"keywords": [
"authenticator",
@ -19,17 +22,20 @@
"base32",
"code",
"generator",
"one-time",
"time-based",
"authy",
"google",
"microsoft"
],
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.com/)",
"license": "Apache-2.0",
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)",
"license": "(MIT or Apache-2.0)",
"bugs": {
"url": "https://github.com/Daplie/node-authenticator/issues"
"url": "https://git.coolaj86.com/coolaj86/node-authenticator.js/issues"
},
"homepage": "https://github.com/Daplie/node-authenticator#readme",
"homepage": "https://git.coolaj86.com/coolaj86/node-authenticator.js#readme",
"dependencies": {
"authenticator-cli": "^1.0.5",
"notp": "^2.0.3",
"thirty-two": "0.0.2"
}