Bandwidth Two Factor Authentication Node.js Client
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

Bandwidth BW2fa-Client

Node.js client implementation for bw2fa-server

TwoFactorAuthClient

Usage

var TwoFactorAuthClient = require('bw2fa-client');

new TwoFactorAuthClient(endpoint, accessCode)

  • endpoint {string) - bw2fa-server base uri
  • accessCode {string) - bw2fa-server access code
var TwoFactorAuthClient = require('bw2fa-client');

var bw2fa = new TwoFactorAuthClient({
  "http://my-bw2fa-server.com/",
  "mySuperSecretAccessCode"
});

sendCode(from, to, callback)

Create a new session and send a verification code to a user's mobile device.

  • from {string} - E.164 formatted number to send verification code from. This should be a number that has already been provisioned on your catapult account.
  • to {string} - E.164 formatted number to send verification code to. In practice this is the end user's mobile phone number.
  • callback {function} - Function with signature (error, session)
    • error {object} - Error or null.
    • session {string} - encrypted session token to be passed back to user.
bw2fa.sendCode('+15555555555', '+16666666666', function (error, session) {
    if (error) {
        console.log(JSON.stringify(error));
    } else {
        console.log(session);
    }
});

codeIsValid(session, code, callback)

Check to see if the provided code matches the one sent to a user's mobile device.

  • session {string} - encrypted session token.
  • code {string} - User provided verification code.
  • callback {function} - Function with signature (error, isValid)
    • error {object} - Error or null.
    • isValid {string} - True if user provided the correct verification code. False if code is incorrect or session is expired.
bw2fa.codeIsValid('Fe26.2**da4f2...', '123456', function (error, isValid) {
    if (error || !isValid) {
        console.log(error);
    } else {
        console.log('Verified!!!');
    }
});

Run tests, check code style:

npm test