gatekeeper-express
The one and only Two Factor Authentication Handler for Express.
Tested with Authy
, Google Authenticator
and Duo
.
Install
npm i gatekeeper-express
Peer dependencies
npm i lodash express
Requirements
- express-session
- passport (ie.
req.user
) - some rendering engine (vash, ejs, etc)
Usage
Middleware
'use strict'; const GateKeeper = ; const gateKeeper = appName: 'App' length: 64; app;
View
GateKeeper uses res.render('two-fa')
to render the page with qr image.
This is an example in Vash. Please adapt it to your app.
Two Factor Authentication @if (model.qrImage) { } Verify
AJAX
You can also use Ajax.
If you request /tfa
with Ajax it will send back in JSON: { qrImage: string; verifyUrl: string; }
Do a POST
request to verifyUrl
and GateKeeper will send back a JSON
object with a redirect url to use: { redirect: string; }
if needed.
Reset
To reset a user's 2-fa, simply delete user.tfa
.
Made with ❤ at Income Store in Lancaster, PA.