What is Authy Verification API?
Authy is a more complete authentication API and best for an ongoing relationship with a customer. Authy provides SMS and voice time-based one-time password(OTP). Its primary use is two-factor Authentication(2FA). It supports OTP send via voice and SMS.
Purpose of phone number verification
1) Phone number verification is the process of verifying a phone number is valid, reachable and accessible by the user.
2) Phone number verification is used as a form of two-factor authentication.
3) Phone verification can be done by SMS or by voice.
Things needed before starting
1) Twilio account by visiting https://www.twilio.com/try-twilio
2) Authy app which you can create in Twilio console from where you will need an API key.
3) Ruby version: 2.5.1 and rails version: 5.2.3
1) Create a new application in rails: rails new application_name
2) cd application_name is used to go to a particular file.
3) Go to gemfile and add
4) Run bundle install
5) Initialize envyable from the command line by running the command
bundle exec envyable install
and add authy api key
7) Create a file authy.rb in config/initializer and add the following code
Authy.api_key = ENV['AUTHY_API_KEY']
Authy.api_uri = 'https://api.authy.com/'
The process for Phone number verification include
1) Three information
1.1) Country code.
1.2) Phone number.
1.3) methods to verify phone number includes SMS or Voice.
Application which we have created in rails make a request to
to initiate verification.
3) If a user chose a SMS method then, user will get a text message with a 4-digit code.
4) User enter a 4-digit code into a form.
5) The code is sent to Authy API with a country code and phone number. If a entered 4-digit code is correct then User has verified a number.
Building an app
1)First, create a controller by running a command
rails generate controller phone_verifications
2) To generate a list of country code so that we can search by country code of the particular country.
Add this in app/views/layouts/application.html.erb
<%= stylesheet_link_tag https://cdnjs.cloudflare.com/ajax/libs/authy-form-helpers/2.3/form.authy.min.css', media: 'all', 'data-turbolinks-track': 'reload' %>
3) Create a new file as new.html.erb in app/views/your_application_name/new.html.erb
add a code for country code and phone number and verification methods such as SMS and call
4) Run server to see whether we are getting a mobile verification form or not.
5) The most important task is to create a method in the controller where country code and phone number parameters are passed. The session is used to store data.
6) After entering all details in mobile verification there should be a form where user can enter OTP received in mobile either by receiving a text message or by voice. For creating a text field to enter OTP I have created challenge.html.erb in views.
7) Verify method is created in the controller to verify entered OTP is correct or not. Here PhoneVerification.check passing of all parameter of phone number verification form.
8) If an OTP entered by the user is correct then there should be a message as congratulation your entered OTP is correct. We can do this by creating a success.html.erb in app/views/phone_verifications/success.html.erb as
<p>You have successfully verified your Phone Number.</p>
9) Run a server to see phone verification by using either an SMS or Voice method is working properly.
rails s command is used to run a server.
In phone number verification by voice or SMS, we have created a controller. It can be done with the help of model to save records in the database for phone number.