🚀 Socket Launch Week 🚀 Day 5: Introducing Socket Fix.Learn More
Socket
Sign inDemoInstall
Socket

hapi-authy

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-authy

Authy 2FA with hapi

1.0.5
latest
Source
npm
Version published
Maintainers
1
Created
Source

hapi-authy Build Status

Two-Factor Authentication with Authy and hapi

This is a plugin that you can use to add 2fa to your hapi apps with ease. It works with the Authy service. Head over to Authy and register for an account.

Check out the example under examples/basic for a full working example of form based email/password and authy authentication (Authy API Key required)

Getting started

  • Register with Authy
  • Create an app
  • Grab your api key

Installation

npm install --save hapi-authy

Usage

This would normally be used to implement the second step in a login process. After a successful step 1 (usually username/password login), a user with a 2fa-enabled account would be redirected to the 2fa route. Everything is then handled by the plugin.

This plugins defines a hapi auth scheme called authy. To get started, create a strategy from this scheme:

server.auth.strategy('authy', 'authy', {
    apiKey: 'your api key',
    sandbox: false,
    cookieOptions: {
        isSecure: false,
        path: '/',
        encoding: 'iron',
        password: 'cookiepass'
    }
});

Then define the 2FA route where you will redirect users to:

server.route({
    method: ['GET', 'POST'],
    path: '/authy',
    config: {
        auth: {
            strategies: ['authy'],
            payload: true
        },
        handler: function (request, reply) {

            const credentials = request.auth.credentials; // user's email and authyId
            const user = users[credentials.email];
            user.requireTfa = true;                       // user's account updated to use 2fa
            user.authyId = credentials.authyId;           // authyId saved for future logins
            request.auth.session.set(user);               // user logged in
            return reply.redirect('/');
        }
    }
});

The plugin will then take over fetching the relevant information from the user. The handler for this route will be finally executed once the user has successfully entered their 2FA token, either via SMS or the vis from the Authy app.

step1 step2 step3

Configuration/customisation

Section coming soon. Please checkout examples for now.

Keywords

2fa

FAQs

Package last updated on 02 Nov 2015

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