Giter VIP home page Giter VIP logo

authy-workshop-node's Introduction

Two-Factor Authentication with Authy OneTouch REST APIs and Node.js

Here you will learn how to use the Authy OneTouch REST APIs to perform a user registration, send an approval request, poll the status of the request, display transaction information, etc.

Learn more about this code in our interactive code walkthrough.

Quickstart

Create a Twilio account

Create a free Twilio account and access the Authy dashboard.

You can follow the step by step guide provided here.

Make sure you enable the OneTouch feature in the Authy app that you're creating.

Download the Authy Mobile app

Download and activate the Authy mobile app from the Apple AppStore or Google Play

Setup the environment

This example assumes you already have Node.js already installed on your machine.

This project is built using the Express web framework.

  1. First clone this repository and cd into it.

    $ git clone https://github.com/mjabali/authy-workshop-node.git
    $ cd authy-workshop-node
  2. Install the dependencies.

    $ npm install
  3. Export the environment variable (AUTHY_API_KEY).

    You can find your AUTHY API KEY for Production at https://dashboard.authy.com/.

    $ export AUTHY_API_KEY=Your Authy API Key

    If you are using a non-UNIX operating system, make sure that the AUTHY_API_KEY is loaded into your environment.

  4. Run the server.

    $ npm start
  5. Open up your web browser and navigate to http://localhost:3000

That's it!

Workshop Objectives

The objectives of this workshop are for you to successfully register a new Authy user in your application, send an Authy OneTouch transaction approval request to your Authy app, approve or deny the ficticious money transfer transaction and display the completed transaction.

####Register the User Before you can secure a user's login or enforce a second factor you need to create an Authy user. Authy requires you send an email, cellphone and country code for each Authy user. In response you get an Authy ID which you must then store with your user's profile in your own application.

The API Endpoint documentation for enabling two-factor authentication for a user is located here

In this sample, we are using the Authy API library for Node.js.

Using the Authy library, here is an example API call for registering the user:

authy.register_user('[email protected]', '555-555-5555', '1',function (err, res) {
    // res = {user: {id: 1337}} where 1337 = Authy Id assigned to the user 
});

####Creating the Approval Request This is the main endpoint. This will create a new approval request for the given Authy ID and send it to the end user along with a push notification to the Authy smartphone application.

The API Endpoint documentation for Creating the Approval Request is located here

Here is an example API call for creating an approval request:

authy._request( "POST",
				"/onetouch/json/users/<USER_AUTHY_ID>/approval_requests?api_key=<AUTHY_API_KEY>",
				{message: "Transfer Money Request",
				 	details: {
					 	"Account Number":"12345",
					 	"Amount":10
				 	},
				seconds_to_expire: 120
			 	}, function(err, res){
					//res = {"approval_request":{"uuid":"550e8400-e29b-41d4-a716-446655440000"},"success":true}
				});

####Checking for Approval Request Status

The final step is to provide the status of the approval request to the user (typically approved or denied).

The API Endpoint documentation for Checking for Approval Request Status is located here

Here is an example API call for checking for Approval Request Status:

authy._request( "GET", 
				"/onetouch/json/approval_requests/<UUID>?api_key=<AUTHY_API_KEY>",
				null, 
				function(err, res){
					//res = {"approval_request": {"status": "pending"},"success": true}
				});

Running our complete solution

If you want to see a complete solution running, navigate to the solution folder under your project and run the server from there.

$ cd solution
$ npm start

Meta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.