Member-only story
Ruby on Rails: Setting up Duo Two-factor Authentication with Devise
- Sign up for a Duo Account: https://signup.duo.com/
- Login to the Duo Admin Panel: https://admin.duosecurity.com
- Click “Protect an Application” and locate Web SDK, click “protect this application”
- Add the Integration Key, Secret Key and API hostname to your .env file
5. Generate a random 40 character string and add it to your .env file as your DUO akey
SecureRandom.gen_random(40)
6. Add gem ‘duo_web’, ‘~> 1.0’
to your Gemfile and run bundle install
7. Change the route for authenticated users to a new method in a controller that inherits from Devise
8. Inside that method, add the following code to the controller that inherits from Devise:
The last parameter should be unique to the current user (uuid, email, etc…)
9. Create a new duo.html.erb file in your view with the following code:
10. Add this script to the top of your duo.html.erb page:
<script src="https://api.duosecurity.com/frame/hosted/Duo-Web-v2.js" type="text/javascript"></script>
11. Create a new route POST route to authenticate the Duo login: