{"_id":"passport-2fa-totp","_rev":"6-fe26b30a861e7e5250ac3dea6282380a","name":"passport-2fa-totp","description":"TOTP based Two-Factor Authentication for Passport and Node.js","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"passport-2fa-totp","version":"0.0.1","description":"TOTP based Two-Factor Authentication for Passport and Node.js","main":"./lib","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/ilich/passport-2fa-totp.git"},"keywords":["totp","opt","auth","authentication","security","passport"],"author":{"name":"Ilya Verbitskiy"},"license":"MIT","bugs":{"url":"https://github.com/ilich/passport-2fa-totp/issues"},"homepage":"https://github.com/ilich/passport-2fa-totp#readme","dependencies":{"notp":"^2.0.3","passport-strategy":"^1.0.0","qr-image":"^3.1.0","thirty-two":"^1.0.1"},"devDependencies":{"chai":"^3.5.0","chai-passport-strategy":"^1.0.0","mocha":"^2.4.5"},"gitHead":"46bbed3543c2c37983cc94f167dc67eb43ca3d14","_id":"passport-2fa-totp@0.0.1","_shasum":"953890d6d4e8b00f31ab550d94e19802f09c83d2","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.5.0","_npmUser":{"name":"ilich","email":"iverbitskiy@gmail.com"},"dist":{"shasum":"953890d6d4e8b00f31ab550d94e19802f09c83d2","tarball":"https://registry.npmjs.org/passport-2fa-totp/-/passport-2fa-totp-0.0.1.tgz","integrity":"sha512-OfztRsFPHfuV49ADrE3mAlhFZIgAxGviXWgMwt+xFWcjdoAOT0r0hHkAzj5h98gNIaSFSkIV6XbDG+uBH9txrw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCwCrZXUBoPh24KPmvPNTcmg8sf76NuvpzkoAyjmzS38gIhAIj2InQ1fyyGI9bU4HJVyTp9MWHMXd5JqBVUXHKJkVNm"}]},"maintainers":[{"name":"ilich","email":"iverbitskiy@gmail.com"}],"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/passport-2fa-totp-0.0.1.tgz_1455579587745_0.499728883150965"}}},"readme":"# passport-2fa-totp\r\n\r\n[![Build Status](https://travis-ci.org/ilich/passport-2fa-totp.svg?branch=master)](https://travis-ci.org/ilich/passport-2fa-totp)\r\n\r\n[Passport](http://passportjs.org/) strategy for Two-factor authenticating with a username, password and TOTP code.\r\n\r\nThis module lets you authenticate using a username, password and TOTP code in your Node.js applications. By plugging into Passport, 2FA TOTP authentication can be easily and unobtrusively integrated into any application or framework that supports [Connect](http://www.senchalabs.org/connect/)-style middleware, including [Express](http://expressjs.com/). You can use any TOTP code generators to generate one-time passwords, for example [Google Authenticator](https://github.com/google/google-authenticator).\r\n\r\n## Install\r\n\r\n```bash\r\n$ npm install passport-2fa-totp\r\n```\r\n\r\n## Usage\r\n\r\n#### Configure Strategy\r\n\r\nThe 2FA TOTP authentication strategy authenticates a user using a username, password and TOTP value generated by a hardware device or software application (known as a token). The strategy requires a callback to verify a username and password and a callback to setup TOTP generator.\r\n\r\n```js\r\nvar GoogleAuthenticator = require('passport-2fa-totp').GoogeAuthenticator;\r\nvar TwoFAStartegy = require('passport-2fa-totp').Strategy;\r\n\r\n...\r\n\r\npassport.use(new TwoFAStartegy(function (username, password, done) {\r\n    // 1st step verification: username and password\r\n    \r\n    User.findOne({ username: username }, function (err, user) {\r\n        if (err) { return done(err); }\r\n        if (!user) { return done(null, false); }\r\n        if (!user.verifyPassword(password)) { return done(null, false); }\r\n        return done(null, user);\r\n    });\r\n}, function (user, done) {\r\n    // 2nd step verification: TOTP code from Google Authenticator\r\n    \r\n    if (!user.secret) {\r\n        done(new Error(\"Google Authenticator is not setup yet.\"));\r\n    } else {\r\n        // Google Authenticator uses 30 seconds key period\r\n        // https://github.com/google/google-authenticator/wiki/Key-Uri-Format\r\n        \r\n        var secret = GoogleAuthenticator.decodeSecret(user.secret);\r\n        done(null, secret, 30);\r\n    }\r\n}));\r\n```\r\n\r\n`GoogleAuthenticator` object provides utility methods for Google Authenticator\r\n\r\n`GoogleAuthenticator.register(username)` - Generate a secret key and render a QR code (SVG) to register an account in Google Authenticator.\r\n\r\n`GoogleAuthenticator.decodeSecret(secret)` - Convert BASE 32 encoded string to byte array.\r\n\r\n##### Available Options\r\n\r\nThis strategy takes an optional options hash before the function, e.g. `new TwoFAStartegy({/* options */, verifyUsernameAndPasswordCallback, verifyTotpCodeCallback})`.\r\n\r\nThe available options are:\r\n\r\n* `usernameField` - Optional, defaults to 'username'\r\n* `passwordField` - Optional, defaults to 'password'\r\n* `codeField` - Optional, defaults to 'code'\r\n* `window` - Optional defaults to 6. A window to generate TOTP code.\r\n* `skipTotpVerification` - Optional defaults to false. TOTP code verification is skipped if it is set to be true.\r\n* `passReqToCallback` - Optional defaults to false. Pass `request` object to the callbacks if it is set to be true.\r\n\r\n#### Authenticate Requests\r\n\r\nUse `passport.authenticate()`, specifying the '2fa-totp' strategy, to authenticate requests.\r\n\r\n```js\r\nrouter.post('/', passport.authenticate('2fa-totp', {\r\n    successRedirect: '/',\r\n    failureRedirect: '/login'\r\n}));\r\n```\r\n\r\n## Examples\r\n\r\nDevelopers using the popular [Express](http://expressjs.com/) web framework can refer to an [node-2fa](https://github.com/ilich/node-2fa) as a starting point for their own web applications.\r\n\r\n## Tests\r\n\r\n```bash\r\n$ npm install\r\n$ npm test\r\n```","maintainers":[{"name":"ilich","email":"iverbitskiy@gmail.com"}],"time":{"modified":"2022-06-23T12:11:50.908Z","created":"2016-02-15T23:39:52.788Z","0.0.1":"2016-02-15T23:39:52.788Z"},"homepage":"https://github.com/ilich/passport-2fa-totp#readme","keywords":["totp","opt","auth","authentication","security","passport"],"repository":{"type":"git","url":"git+https://github.com/ilich/passport-2fa-totp.git"},"author":{"name":"Ilya Verbitskiy"},"bugs":{"url":"https://github.com/ilich/passport-2fa-totp/issues"},"license":"MIT","readmeFilename":"README.md","users":{"yhnavein":true,"temasm":true,"71emj1":true}}