Skip to content

Latest commit

 

History

History
 
 

verify-totp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Twilio Verify Time-based One-time passwords (TOTP)

This demo of the Twilio Verify API includes the TOTP factor type for supporting authenticator apps like Authy or Google Authenticator.

Pre-requisites

Environment variables

This project requires some environment variables to be set. To keep your tokens and secrets secure, make sure to not commit the .env file in git. When setting up the project with twilio serverless:init ... the Twilio CLI will create a .gitignore file that excludes .env from the version history.

In your .env file, set the following values:

Variable Meaning Required
ACCOUNT_SID Find in the console Yes
AUTH_TOKEN Find in the console Yes
VERIFY_SERVICE_SID Create one here Yes

Function Parameters

create-factor.js expects the following parameters:

Parameter Description Required
name An identifier that is used in the authenticator app account name. Yes

verify-new-factor.js expects the following parameters:

Parameter Description Required
identity Unique identity UUID. Returned from create-factor function. Yes
factorSid Starts with YF. Returned from create-factor function. Yes
code Collected from user input. Yes

verify-new-factor will also return backup codes in the response.

create-challenge.js expects the following parameters:

Parameter Description Required
identity Unique identity UUID. Returned from create-factor function. Yes
factorSid Starts with YF. Returned from create-factor function. Yes
code Collected from user input. Yes

Create a new project with the template

  1. Install the Twilio CLI
  2. Install the serverless toolkit
twilio plugins:install @twilio-labs/plugin-serverless
  1. Initiate a new project
twilio serverless:init totp-sample-app --template=verify-totp && cd totp-sample-app
  1. Add your environment variables to .env:

Make sure variables are populated in your .env file. See Environment variables.

  1. Start the server :
twilio serverless:start
  1. Open the web page at https://localhost:3000/index.html and enter your phone number to test

ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables.

Deploying

Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. More details in the docs.

With the Twilio CLI:

twilio serverless:deploy