All Projects → dburles → meteor-two-factor

dburles / meteor-two-factor

Licence: MIT license
🔐 Two factor authentication package for accounts-password

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to meteor-two-factor

Meteor Files
🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
Stars: ✭ 1,033 (+1191.25%)
Mutual labels:  meteor, meteor-package
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (-81.25%)
Mutual labels:  meteor, meteor-package
Ostrio Neo4jdriver
Most advanced and efficient Neo4j REST API Driver, with support of https and GrapheneDB
Stars: ✭ 55 (-31.25%)
Mutual labels:  meteor, meteor-package
meteor-subscription-scope
Scope queries on collections to subscriptions
Stars: ✭ 20 (-75%)
Mutual labels:  meteor, meteor-package
blaze-integration
Vue integration with Meteor's Blaze rendering engine.
Stars: ✭ 24 (-70%)
Mutual labels:  meteor, meteor-package
Ostrio Analytics
📊 Visitor's analytics tracking code for ostr.io service
Stars: ✭ 9 (-88.75%)
Mutual labels:  meteor, meteor-package
Meteor Transactions
App level transactions for Meteor + Mongo
Stars: ✭ 115 (+43.75%)
Mutual labels:  meteor, meteor-package
Meteor Collection Helpers
⚙️ Meteor package that allows you to define helpers on your collections
Stars: ✭ 504 (+530%)
Mutual labels:  meteor, meteor-package
Meteor Google Maps
🗺 Meteor package for the Google Maps Javascript API v3
Stars: ✭ 198 (+147.5%)
Mutual labels:  meteor, meteor-package
Meteor Peerdb
Reactive database layer with references, generators, triggers, migrations, etc.
Stars: ✭ 128 (+60%)
Mutual labels:  meteor, meteor-package
Meteor-Cookies
🍪 Isomorphic bulletproof cookie functions for client and server
Stars: ✭ 41 (-48.75%)
Mutual labels:  meteor, meteor-package
Meteor-Template-helpers
Template helpers for Session, logical operations and debug
Stars: ✭ 35 (-56.25%)
Mutual labels:  meteor, meteor-package
Mongol Meteor Explore Minimongo Devtools
In-App MongoDB Editor for Meteor (Meteor DevTools)
Stars: ✭ 846 (+957.5%)
Mutual labels:  meteor, meteor-package
Autocms
AutoCms is a simple solution for your Meteor.js app
Stars: ✭ 34 (-57.5%)
Mutual labels:  meteor, meteor-package
Vue Meteor
🌠 Vue first-class integration in Meteor
Stars: ✭ 893 (+1016.25%)
Mutual labels:  meteor, meteor-package
Meteor Comments Ui
Simple templates for comment functionality in your Meteor App
Stars: ✭ 78 (-2.5%)
Mutual labels:  meteor, meteor-package
Meteor Easy Search
Easy-to-use search for Meteor with Blaze Components
Stars: ✭ 438 (+447.5%)
Mutual labels:  meteor, meteor-package
Blaze
🔥 Meteor Blaze is a powerful library for creating live-updating user interfaces
Stars: ✭ 474 (+492.5%)
Mutual labels:  meteor, meteor-package
Meteor Reactive Publish
Reactive publish endpoints
Stars: ✭ 123 (+53.75%)
Mutual labels:  meteor, meteor-package
meteor-computed-field
Reactively computed field for Meteor
Stars: ✭ 18 (-77.5%)
Mutual labels:  meteor, meteor-package

Meteor Two Factor

Simple two factor authentication for accounts-password.

Table of Contents

Installation

$ meteor add dburles:two-factor

Prerequisites

Make sure your project is using Meteor's accounts-password package, if not add it: meteor add accounts-password

Example Application

Simple example application

Usage

Client and server usage examples.

Usage (Client)

Typically you would call this method via your application login form event handler:

twoFactor.getAuthCode(user, password, error => {
  if (error) {
    // Handle the error
  }
  // Success!
});

After calling getAuthCode if you wish, you can request a new authentication code:

twoFactor.getNewAuthCode(error => {
  if (error) {
    // Handle the error
  }
  // Success!
});

The following method is reactive and represents the state of authentication. Use it to display the interface to enter the authentication code:

Tracker.autorun(function() {
  if (twoFactor.isVerifying()) {
    console.log('Ready to enter authentication code!');
  }
});

Capture the authentication code and pass it to the following method to validate the code and log the user in:

twoFactor.verifyAndLogin(code, error => {
  if (error) {
    // Handle the error
  }
  // Success!
});

Usage (Server)

Assign a function to twoFactor.sendCode that sends out the code. The example below sends the user an email:

twoFactor.sendCode = (user, code) => {
  // Don't hold up the client
  Meteor.defer(() => {
    // Send code via email
    Email.send({
      to: user.email(), // Method attached using dburles:collection-helpers
      from: '[email protected]',
      subject: 'Your authentication code',
      text: `${code} is your authentication code.`
    });
  });
};

Optional functions:

// Optional
// Conditionally allow regular or two-factor sign in
twoFactor.validateLoginAttempt = options => {
  // If two factor auth isn't enabled for this user, allow regular sign in.
  return !options.user.twoFactorEnabled;
};
// Optional
twoFactor.generateCode = () => {
  // return a random string
};

Security note:

Use DDPRateLimiter to prevent verification code cracking

import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';

const numberOfAttempts = 5;
const timeInterval = 60;

DDPRateLimiter.addRule(
  {
    type: 'method',
    userId: null,
    clientAddress: null,
    name(name) {
      const methods = [
        'twoFactor.verifyCodeAndLogin',
        'twoFactor.getAuthenticationCode'
      ];
      return methods.includes(name);
    },
    connectionId() {
      return true;
    }
  },
  numberOfAttempts,
  timeInterval * 1000
);

API

The following functions are attached to the twoFactor namespace. This may change somewhat for Meteor 1.3.

API (Client)

getAuthCode

getAuthCode(user, password, [callback])

Generates an authentication code. Once generated, (by default) a twoFactorCode field is added to the current user document. This function mirrors Meteor.loginWithPassword.

user Either a string interpreted as a username or an email; or an object with a single key: email, username or id. Username or email match in a case insensitive manner.

password The user's password.

callback Optional callback. Called with no arguments on success, or with a single Error argument on failure.

getNewAuthCode

getNewAuthCode([callback])

Generates a new authentication code. Only functional while verifying.

callback Optional callback. Called with no arguments on success, or with a single Error argument on failure.

verifyAndLogin

verifyAndLogin(code, [callback])

Verifies authentication code and logs in the user.

code The authentication code.

callback Optional callback. Called with no arguments on success, or with a single Error argument on failure.

isVerifying

isVerifying()

Reactive function that indicates the current state between having generated an authentication code and awaiting verification.

abort

abort([callback])

Call this function while verifying if you wish to allow the user to sign in again.

callback Optional callback. Called with no arguments on success, or with a single Error argument on failure.

API (Server)

sendCode

sendCode(user, code)

This function is called after getAuthCode is successful.

user The current user document.

code The generated authentication code.

options

twoFactor.options.fieldName = 'customFieldName';

Specify the name of the field on the user document to write the authentication code. Defaults to twoFactorCode.

validateLoginAttempt (Optional)

validateLoginAttempt(options)

If defined, this function is called within an Accounts.validateLoginAttempt callback. Use this to allow regular login under certain conditions.

generateCode (Optional)

If defined, this function is called to generate the random code instead of the default.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].