est to our app with an approved status.
- We log the user in.
When our user logs in we immediately attempt to verify their identity with OneTouch. We will fallback gracefully if they don't have a OneTouch device, but we don't know until we try.
Authy allows us to input details with our OneTouch request, including a message, a logo and so on. We could easily send any amount of details by appending
details['some_detail']. You could imagine a scenario where we send a OneTouch request to approve a money transfer.
"message" => "Request to Send Money to Jarod's vault", "details['Request From']" => "Jarod", "details['Amount Request']" => "1,000,000", "details['Currency']" => "Galleons",
Once we send the request we need to update our User's
authy_status based on the response. But first we have to register a OneTouch callback endpoint.
In order for our app to know what the user did after we sent the OneTouch request, we need to register a callback endpoint with Authy.
Note: In order to verify that the request is coming from Authy, we've written the helper method
authenticate_request! that will halt the request if it appears it isn't coming from Authy.
Here in our callback, we look up the user using the Authy ID sent with the Authy POST request. Ideally at this point we would probably use a websocket to let our client know that we received a response from Authy. However for this version we're going to keep it simple and just update the
authy_status on the User.
Our application is now capable of using Authy for two-factor authentication. However, we are still missing an important part: the client-side code that will handle it.
When we expect a OneTouch response, we will begin by polling
/authy/status until we see an Authy status is not empty. Let's take a look at this controller and see what is happening.
Let's take a closer look at how we check the login status on the server.
authy_status is approved the user will be redirected to the protected content, otherwise we'll show the login form with a message that indicates the request was denied.
That's it! We've just implemented two-factor auth using three different methods and the latest in Authy technology.
If you're a Ruby developer working with Twilio, you might enjoy these other tutorials:
Protect your users' privacy by anonymously connecting them with Twilio Voice and SMS. Learn how to create disposable phone numbers on-demand, so two users can communicate without exchanging personal information.
Use Twilio to track the effectiveness of your marketing campaigns.
Thanks for checking out this tutorial! If you have any feedback to share with us, we'd love to hear it. Connect with us on Twitter and let us know what you build!