From f0da6f3db89ebf365f985c5d65c092ce08bcdf45 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 2 Jan 2016 01:09:19 -0800 Subject: [PATCH] initial commit --- README.md | 43 ++++++++++++++++++++++++++++++++++- bin/authenticator.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100755 bin/authenticator.js create mode 100644 package.json diff --git a/README.md b/README.md index d9cc55a..2888ade 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,43 @@ # authenticator-cli -A commandline Authenticator App (for Authy, Google Authenticator, Microsoft Authenticator, TOTP, etc) + +A commandline Authenticator App (for Authy, Google Authenticator, Microsoft Authenticator, Facebook Authenticator, TOTP, etc) + +**Install node.js 4.0+**: + +```bash +curl -L https://bit.ly/iojs-min | bash +``` + +**Install authenticator**: +```bash +npm install --global authenticator-cli +``` + +``` +Usage: + authenticator [OPTIONS] + +Options: + --account user@example.com Account Name, typically email address (Default is user@example.com) + + --algo SHA1 Algorithm, typically SHA1 (also SHA256, SHA512) (Default is SHA1) + + --digits 6 Number of digits, typically 6 (also 8) (Default is 6) + + --generate Create a cryptographically-random TOTP key + formatted in base32 with spaces. (Default is true) + + --issuer ACME Issuer, typically the company name (Google, + Facebook, Digital Ocean, etc) (Default is ACME) + + --key 'xxxx xxxx ...' Supply the base32 key yourself (with or without + delimeters). Takes precedence over --generate + + --period 30 Number of seconds between tokens, typically 30 (Default is 30) + + --qr Print the QR Code to the Terminal. + + --verify '123 456' Verify a token. Must be used with --key. + + -h, --help Display help and usage details +``` diff --git a/bin/authenticator.js b/bin/authenticator.js new file mode 100755 index 0000000..4ba91ae --- /dev/null +++ b/bin/authenticator.js @@ -0,0 +1,53 @@ +#!/usr/bin/env node +'use strict'; + +var cli = require('cli'); +var authenticator = require('authenticator'); +var qrcode = require('qrcode-terminal'); + +cli.parse({ + account: [ false, "Account Name, typically email address", 'string', 'user@example.com' ] +, algo: [ false, "Algorithm, typically SHA1 (also SHA256, SHA512)", 'string', 'SHA1' ] +, digits: [ false, "Number of digits, typically 6 (also 8)", 'integer', 6 ] +, generate: [ false, "Create a cryptographically-random TOTP key formatted in base32 with spaces.", 'boolean', true ] +, issuer: [ false, "Issuer, typically the company name (Google, Facebook, Digital Ocean, etc)", 'string', 'ACME' ] +, key: [ false, "Supply the base32 key yourself (with or without delimeters). Takes precedence over --generate", 'string' ] +, period: [ false, "Number of seconds between tokens, typically 30", 'integer', 30 ] +, qr: [ false, "Print the QR Code to the Terminal.", 'boolean', false ] +//, token: [ false, "Print the current token for the given (or generated) key.", 'boolean', false ] +, verify: [ false, "Verify a token. Must be used with --key.", 'string' ] +}); + +// ignore certonly and extraneous arguments +cli.main(function(_, options) { + var key = (options.key || authenticator.generateKey()).toString(); + var token = (options.verify || authenticator.generateToken(key)).toString(); + var url = authenticator.generateTotpUri( + key + , options.account || null + , options.issuer || null + , options.algo || 'SHA1' + , options.digits || 6 + , options.perdiod || 30 + ); + + console.log(''); + console.log('Key:', key); + console.log('Token:', token); + console.log('URL:', url); + + if (options.qr) { + console.log(''); + qrcode.setErrorLevel('L'); // L: 7%, M: 15%, Q: 25%, H: 30% + qrcode.generate(url, function (qr) { + console.log(qr); + }); + } + + if (options.verify) { + console.log(''); + console.log('Verified:', !!authenticator.verifyToken(key, token)); + } + + console.log(''); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5e3df6c --- /dev/null +++ b/package.json @@ -0,0 +1,42 @@ +{ + "name": "authenticator-cli", + "version": "1.0.0", + "description": "A commandline Authenticator App (for Authy, Google Authenticator, Microsoft Authenticator, TOTP / 2FA / MFA / OTP, etc)", + "main": "index.js", + "bin": { + "authenticator-cli": "authenticator.js" + }, + "dependencies": {}, + "devDependencies": {}, + "scripts": { + "test": "node bin/authenticator.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Daplie/authenticator-cli.git" + }, + "keywords": [ + "Authenticator", + "CLI", + "Commandline", + "command", + "line", + "authy", + "google", + "microsoft", + "facebook", + "daplie", + "totp", + "2fa", + "mfa", + "otp", + "one-time", + "password" + ], + "author": "AJ ONeal (https://coolaj86.com/)", + "license": "MPL-2.0", + "bugs": { + "url": "https://github.com/Daplie/authenticator-cli/issues" + }, + "homepage": "https://github.com/Daplie/authenticator-cli#readme" +}