メニュー

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Twilio Authy二要素認証向けのRuby on Railsクイックスタート

For new development, we encourage you to use the Verify API instead of the Authy API. The Verify API is an evolution of the Authy API with continued support for SMS, voice, and email one-time passcodes, an improved developer experience and new features including:

  • Twilio helper libraries in JavaScript, Java, C#, Python, Ruby, and PHP
  • Access via the Twilio CLI
  • Improved Visibility and Insights
  • Push authentication SDK embeddable in your own application

You are currently viewing the Authy API. The Authy API will continue to be maintained, but any new features and development will be on the Verify API. Check out the FAQ for more information and Verify API Reference to get started.

Adding Two-factor Authentication to your application is the easiest way to increase security and trust in your product without unnecessarily burdening your users. This quickstart guides you through building a Ruby and Ruby on Rails application that restricts access to a URL. Four Authy API channels are demoed: SMS, Voice, Soft Tokens and Push Notifications.

Ready to protect a tiny app from malicious hackers?

Sign Up For or Sign Into a Twilio Account

Create a new Twilio account (you can sign up for a free Twilio trial), or sign into an existing Twilio account.

新規Authyアプリケーションを作成する

Once logged in, visit the Authy Console. Click on the red 'Create New Aplication' (or big red plus ('+') if you already created one) to create a new Authy application then name it something memorable.

Authy create new application

You'll automatically be transported to the Settings page next. Click the eyeball icon to reveal your Production API Key.

Account Security API Key

Copy your Production API Key to a safe place, you will use it during application setup.

Setup the Authy Client on Your Device

This Two-factor Authentication demos two channels which require an installed Authy Client to test: Soft Tokens and Push Notifications. While SMS and Voice channels will work without the client, to try out all four authentication channels download and install Authy Client for Desktop or Mobile:

アプリケーションをクローン、セットアップする

Clone our repository locally, then enter the directory. Install all of the necessary ruby modules:

bundle install

Next, open the file config/application.example.yml. There, edit the ACCOUNT_SECURITY_API_KEY, pasting in the API Key from the above step (in the console), and save the file as config/application.yml.

It will be loaded when the application begins.

        
        
        
        
        Enter the API Key from the Authy console.

        Add Your Application API Key

        Enter the API Key from the Authy console.

        Once you have added your API Key, you are ready to run! Launch Rails with:

        ./bin/rails server
        

        If your API Key is correct, you should get a message your new app is running!

        Try the Ruby on Rails Authy Two-Factor Demo

        With your phone (optionally with the Authy client installed) nearby, open a new browser tab and navigate to http://localhost:3000/register/

        Enter your information and invent a password, then hit 'Register'. Your information is passed to Twilio (you will be able to see your user immediately in the console), and the application is returned a user_id.

        Now visit http://localhost:3000/login/ and login. You'll be presented with a happy screen:

        Token Verification Page

        If your phone has the Authy Client installed, you can immediately enter a Soft Token from the client to Verify. Additionally, you can try a Push Authentication simply by pushing the labeled button.

        If you do not have the Authy Client installed, the SMS and Voice channels will also work in providing a token. To try different channels, you can logout to start the process again.

              
              
              
              

              And there you go, Authy two-factor authentication is on and your Rails app is protected!

              関連トピック

              Now that you are keeping the hackers out of this demo app using Twilio Authy two-factor authentication, you can find all of the detailed descriptions of options and API calls in our Authy API Reference. If you're also building a registration flow, also check out our Verify product and the Ruby Phone Verification quickstart which uses this codebase.

              For additional guides and tutorials on account security and other products, in Ruby and in our other languages, take a look at the Docs.

              Rate this page:

              ヘルプが必要ですか?

              誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。