New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gatekeeper-express

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatekeeper-express

The one and only Two Factor Authentication Handler for Express.

  • 1.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gatekeeper-express

The one and only Two Factor Authentication Handler for Express.

Tested with Authy, Google Authenticator and Duo.

You shall not pass

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 } = require('gatekeeper-express');

const gateKeeper = new GateKeeper({
    appName: 'App',
    length: 64
});

app.use(
    gateKeeper.express({
        routePathPrefix: '/tfa',
        userIdPath: 'email',
        onSerialize: async (req, tfa) => {
            req.user.tfa = tfa;
            await req.user.save();
        },
        onDeserialize: async req => {
            return req.user.tfa;
        }
    })
);

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.

<div class="text-center">
    <h4 class="h4 text-gray-900 mb-3">Two Factor Authentication</h4>
</div>

<form autocomplete="off" action="@model.verifyUrl" method="POST" class="user">
    <input autocomplete="off" name="hidden" type="text" style="display:none;">
    @if (model.qrImage) {
        <div class="text-center mb-2">
            <img src="@model.qrImage">
        </div>
    }

    <div class="form-group">
        <input 
            type="text"
            class="form-control form-control-user"
            id="token-input"
            name="token"
            placeholder="Enter verification token...">
    </div>

    <button class="btn btn-primary btn-user btn-block" type="submit">Verify</button>
</form>

<script>$('#token-input').focus();</script>

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.

Keywords

FAQs

Package last updated on 19 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc