authy 2.7.4 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dfb550356bddccbe1f5d993cfbc3037ea22e2813966dd11f90afc8bafbd20eb
4
- data.tar.gz: 340156acebec4f33ea0a5d051a90bafc62a1eacbc1b9ec3e609d3d8d0f955978
3
+ metadata.gz: 23c21d271c8520c2184e573c84ef59ae4a6e132492cfd2a95f4ef58ba8520772
4
+ data.tar.gz: e24159cc202f8cec50127af25ce3364761b7f5f7731f41cbc6a61b55d71c9bed
5
5
  SHA512:
6
- metadata.gz: 511f66970a820e61989f431ae2ee0dc7bd453525f0d50c7ba1a783a2065377e335a97c77177e0e8da982ad422f360b5dd97d2ba3c53f9508bdb51bf45661f9ac
7
- data.tar.gz: e0b8a32414ffe1eb9bb660ff8cb7e0d7c1cd093ea4e7badfda9690eb9edc2c48e3857286f634af60fdc180340f819a5e556f16d4647137b83210e5e8358549de
6
+ metadata.gz: 376d933202cd1a175e70981b78fdc6cdc15c931cce7507e368f30b71b99d40126a3ec89f078569933ce85b9ab3dfce0d21731d67938a742cc7eed4a75be663f4
7
+ data.tar.gz: 73a68a4edb6cb9828ce99a8438098e072c87600d80111965d9400b010d081ba72adbc73ab2e6de248aa32375043c75888a163954b35a81771332bfc2abd20756
@@ -0,0 +1,21 @@
1
+ name: build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [2.5, 2.6, 2.7, "3.0", 3.1, head]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby ${{ matrix.ruby }}
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run tests
21
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -55,3 +55,4 @@ examples/db
55
55
  .ruby-gemset
56
56
  .rvmrc
57
57
 
58
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog for `Authy`
2
+
3
+ ## Final release [☰](https://github.com/twilio/authy-ruby/compare/v3.0.0...v3.0.1)
4
+
5
+ * Major updates
6
+ * Added deprecation notices
7
+
8
+ ## 3.0.0 (14 December, 2020) [☰](https://github.com/twilio/authy-ruby/compare/v2.7.5...v3.0.0)
9
+
10
+ * Major updates
11
+ * Removed Phone Intelligence APIs
12
+ * Deprecated Phone Verification APIs (use the Twilio Verify API instead: https://twil.io/verify-start-ruby)
13
+ * Mocked API requests in tests, removed Sandbox API
14
+ * Minor updates
15
+ * Added API calls for requesting an email and updating a user's email address (#68)
16
+ * Removed polyfills for try_convert
17
+ * Updates to insecure dependencies
18
+
19
+ ## 2.7.5 and older
20
+
21
+ Please check the [commit log](https://github.com/twilio/authy-ruby/compare/f9e9236...v2.7.5).
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'httpclient', ">= 2.5.3.3"
4
-
5
- group :development do
6
- gem "rspec"
7
- gem 'pry'
8
- gem "yard", "~> 0.9.11"
9
- gem "rdoc"
10
- gem "jeweler"
11
- gem "simplecov", ">= 0"
12
- gem "reek"
13
- end
3
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2020 Authy Inc
1
+ Copyright (c) 2011-2021 Authy Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,232 +1,107 @@
1
- # Authy [![Build Status](https://travis-ci.org/authy/authy-ruby.png?branch=master)](https://travis-ci.org/authy/authy-ruby) [![Code Climate](https://codeclimate.com/github/authy/authy-ruby.png)](https://codeclimate.com/github/authy/authy-ruby)
1
+ [![Gem Version](https://badge.fury.io/rb/authy.svg)](https://rubygems.org/gems/authy/) [![Build Status](https://github.com/twilio/authy-ruby/workflows/build/badge.svg)](https://github.com/twilio/authy-ruby/actions) [![Code Climate](https://codeclimate.com/github/authy/authy-ruby.png)](https://codeclimate.com/github/authy/authy-ruby)
2
2
 
3
- Ruby library to access the Authy API
3
+ ---
4
4
 
5
- ## Usage
6
-
7
- ```ruby
8
- require 'authy'
5
+ 🚨🚨🚨
9
6
 
10
- Authy.api_key = 'your-api-key'
11
- Authy.api_uri = 'https://api.authy.com'
12
- ```
7
+ **This library is no longer actively maintained.** The Authy API has been replaced with the [Twilio Verify API](https://www.twilio.com/docs/verify). Twilio will support the Authy API through November 1, 2022 for SMS/Voice. After this date, we’ll start to deprecate the service for SMS/Voice. Any requests sent to the API after May 1, 2023, will automatically receive an error. Push and TOTP will continue to be supported through July 2023.
13
8
 
14
- Using Ruby on Rails? _Put this in **config/initializers** and create a new file called **authy.rb**._
9
+ [Learn more about migrating from Authy to Verify.](https://www.twilio.com/blog/migrate-authy-to-verify)
15
10
 
16
- ## Registering a user
11
+ Please visit the Twilio Docs for:
12
+ * [Verify + Ruby (Rails) quickstart](https://www.twilio.com/docs/verify/quickstarts/ruby-rails)
13
+ * [Twilio Ruby helper library](https://www.twilio.com/docs/libraries/ruby)
14
+ * [Verify API reference](https://www.twilio.com/docs/verify/api)
17
15
 
18
- __NOTE: User is matched based on cellphone and country code not e-mail.
19
- A cellphone is uniquely associated with an authy_id.__
16
+ Please direct any questions to [Twilio Support](https://support.twilio.com/hc/en-us). Thank you!
20
17
 
18
+ 🚨🚨🚨
21
19
 
22
- `Authy::API.register_user` requires the user e-mail address and cellphone. Optionally you can pass in the country_code or we will asume
23
- USA. The call will return you the authy id for the user that you need to store in your database.
20
+ ---
24
21
 
25
- Assuming you have a `users` database with a `authy_id` field in the `users` database.
26
22
 
27
- ```ruby
28
- authy = Authy::API.register_user(:email => 'users@email.com', :cellphone => "111-111-1111", :country_code => "1")
29
23
 
30
- if authy.ok?
31
- self.authy_id = authy.id # this will give you the user authy id to store it in your database
32
- else
33
- authy.errors # this will return an error hash
34
- end
35
- ```
24
+ # Ruby Client for Twilio Authy Two-Factor Authentication (2FA) API
36
25
 
37
- ## Verifying a user
26
+ Documentation for Ruby usage of the Authy API lives in the [official Twilio documentation](https://www.twilio.com/docs/authy/api/).
38
27
 
28
+ The Authy API supports multiple channels of 2FA:
29
+ * One-time passwords via SMS and voice.
30
+ * Soft token ([TOTP](https://www.twilio.com/docs/glossary/totp) via the Authy App)
31
+ * Push authentication via the Authy App
39
32
 
40
- __NOTE: Token verification is only enforced if the user has completed registration. To change this behaviour see Forcing Verification section below.__
33
+ If you only need SMS and Voice support for one-time passwords, we recommend using the [Twilio Verify API](https://www.twilio.com/docs/verify/api) instead.
41
34
 
42
- >*Registration is completed once the user installs and registers the Authy mobile app or logins once successfully using SMS.*
35
+ [More on how to choose between Authy and Verify here.](https://www.twilio.com/docs/verify/authy-vs-verify)
43
36
 
44
- `Authy::API.verify` takes the authy_id that you are verifying and the token that you want to verify. You should have the authy_id in your database
37
+ ### Authy Quickstart
45
38
 
46
- ```ruby
47
- response = Authy::API.verify(:id => user.authy_id, :token => 'token-user-entered')
39
+ For a full tutorial, check out either of the Ruby Authy Quickstart in our docs:
48
40
 
49
- if response.ok?
50
- # token was valid, user can sign in
51
- else
52
- # token is invalid
53
- end
54
- ```
41
+ * [Ruby/Rails Authy Quickstart](https://www.twilio.com/docs/authy/quickstart/two-factor-authentication-ruby-rails)
55
42
 
56
- ### Forcing Verification
43
+ ## Authy Ruby Installation
57
44
 
58
- If you wish to verify tokens even if the user has not yet complete registration, pass force=true when verifying the token.
59
-
60
- ```ruby
61
- response = Authy::API.verify(:id => user.authy_id, :token => 'token-user-entered', :force => true)
62
45
  ```
63
-
64
- ## Requesting a SMS token
65
-
66
- `Authy::API.request_sms` takes the authy_id that you want to send a SMS token. This requires Authy SMS plugin to be enabled.
67
-
68
- ```ruby
69
- response = Authy::API.request_sms(:id => user.authy_id)
70
-
71
- if response.ok?
72
- # sms was sent
73
- else
74
- response.errors
75
- #sms failed to send
76
- end
46
+ gem install authy
77
47
  ```
78
48
 
79
- This call will be ignored if the user is using the Authy Mobile App. If you still want to send
80
- the SMS pass force=true as an option
81
-
82
- ```ruby
83
- response = Authy::API.request_sms(:id => user.authy_id, :force => true)
84
- ```
85
-
86
- If you wish to send SMS in a specific language, you can provide locale information in the params as shown below.
87
-
88
- ```ruby
89
- response = Authy::API.request_sms(:id => user.authy_id, :force => true, :locale => 'es')
90
- ```
91
-
92
- If the locale that you provide is wrong or does not match, the SMS will be sent in english.
93
-
94
- ## Requesting token via a phone call
95
-
96
- `Authy::API.request_phone_call` takes the authy_id that you want to deliver the token by a phone call. This requires Authy Calls addon, please contact us to support@authy.com to enable this addon.
97
-
98
- ```ruby
99
- response = Authy::API.request_phone_call(:id => user.authy_id)
100
-
101
- if response.ok?
102
- # call was done
103
- else
104
- response.errors
105
- # call failed
106
- end
107
- ```
108
-
109
- This call will be ignored if the user is using the Authy Mobile App. If you ensure that user receives the phone call, you must pass force=true as an option
110
-
111
- ```ruby
112
- response = Authy::API.request_phone_call(:id => user.authy_id, :force => true)
113
- ```
114
-
115
- ## Requesting QR code for authenticator apps like Google Authenticator
116
-
117
- `Authy::API.request_qr_code` takes authy_id that you want to deliver the qr code. This requires **Generic authenticator tokens** to be enabled in Authy console setting. Optinally, you can provide `qr_size` as a number to decide the output of qr image (For example: `qr_size: 400` will returns a 400x400 image) and `label` as a custom label to be shown by the authenticator app.
118
-
119
- ```ruby
120
- response = Authy::API.request_qr_code(id: user.authy_id, qr_size: 500, label: "My Example App")
121
- if response.ok?
122
- # qr code was generated
123
- else
124
- response.errors
125
- end
126
-
127
- # You can access the iamge link with
128
- link = response.qr_code
129
- ```
130
-
131
- ## Deleting users
49
+ ## Usage
132
50
 
133
- `Authy::API.delete_user` takes the authy_id of the user that you want to remove from your app.
51
+ To use the Authy client, require the `authy` gem and initialize it with our API URI and your production API Key found in the [Twilio Console](https://www.twilio.com/console/authy/applications/):
134
52
 
135
53
  ```ruby
136
- response = Authy::API.delete_user(:id => user.authy_id)
137
-
138
- if response.ok?
139
- # the user was deleted
140
- else
141
- response.errors
142
- # we were unavailable to delete the user
143
- end
144
- ```
145
-
146
- ## User status
54
+ require 'authy'
147
55
 
148
- `Authy::API.user_status` takes the authy_id of the user that you want to get the status from your app.
149
-
150
- ```ruby
151
- response = Authy::API.user_status(:id => user.authy_id)
152
-
153
- if response.ok?
154
- # do something with user status
155
- else
156
- response.errors
157
- # the user doesn't exist
158
- end
56
+ Authy.api_uri = 'https://api.authy.com'
57
+ Authy.api_key = 'your-api-key'
159
58
  ```
160
59
 
161
- ## Phone Verification
162
-
163
- ### Starting a phone verification
60
+ Rails users can put this in config/initializers and create a new file called `authy.rb`.
164
61
 
165
- `Authy::PhoneVerification.start` takes a country code, phone number and a method (sms or call) to deliver the code. You can also provide a custom_code but this feature needs to be enabled by support@twilio.com
62
+ ![authy api key in console](https://s3.amazonaws.com/com.twilio.prod.twilio-docs/images/account-security-api-key.width-800.png)
166
63
 
167
- ```ruby
168
- response = Authy::PhoneVerification.start(via: "sms", country_code: 1, phone_number: "111-111-1111")
169
- if response.ok?
170
- # verification was started
171
- end
172
- ```
64
+ ## 2FA Workflow
173
65
 
174
- ### Checking a phone verification
66
+ 1. [Create a user](https://www.twilio.com/docs/authy/api/users#enabling-new-user)
67
+ 2. [Send a one-time password](https://www.twilio.com/docs/authy/api/one-time-passwords)
68
+ 3. [Verify a one-time password](https://www.twilio.com/docs/authy/api/one-time-passwords#verify-a-one-time-password)
175
69
 
176
- `Authy::PhoneVerification.check` takes a country code, phone number and a verification code.
70
+ **OR**
177
71
 
178
- ```ruby
179
- response = Authy::PhoneVerification.check(verification_code: "1234", country_code: 1, phone_number: "111-111-1111")
180
- if response.ok?
181
- # verification was successful
182
- end
183
- ```
72
+ 1. [Create a user](https://www.twilio.com/docs/authy/api/users#enabling-new-user)
73
+ 2. [Send a push authentication](https://www.twilio.com/docs/authy/api/push-authentications)
74
+ 3. [Check a push authentication status](https://www.twilio.com/docs/authy/api/push-authentications#check-approval-request-status)
184
75
 
185
- ## OneTouch Verification
186
76
 
187
- Another way to provide Two_factor authentication with Authy is by using OneTouch feature.
188
- Check the [official docs](http://docs.authy.com/onetouch_getting_started.html)
189
-
190
- `Authy::OneTouch.send_approval_request` takes the Authy user ID, a message to fill up the push notification
191
- body, an optional hash details for the user and another optional hash for hidden details for internal app
192
- control.
193
-
194
- ```ruby
195
- one_touch = Authy::OneTouch.send_approval_request(
196
- id: @user.authy_id,
197
- message: "Request to Login",
198
- details: {
199
- 'Email Address' => @user.email,
200
- },
201
- hidden_details: { ip: '1.1.1.1' }
202
- )
203
- ```
77
+ ## <a name="phone-verification"></a>Phone Verification
204
78
 
205
- As soon as the user approves or reject the push notification, Authy will hit a callback endpoint
206
- (set into Dashboard) updating user's `authy_status` flag. You might have an endpoint in a controller
207
- such as:
79
+ [Phone verification now lives in the Twilio API](https://www.twilio.com/docs/verify/api) and has [Ruby support through the official Twilio helper libraries](https://www.twilio.com/docs/libraries/ruby).
208
80
 
209
- ```ruby
210
- def callback
211
- authy_id = params[:authy_id]
212
- @user = User.find_by authy_id: authy_id
213
- @user.update(authy_status: params[:status])
214
- end
215
- ```
81
+ [Legacy (V1) documentation here.](verify-legacy-v1.md) **Verify V1 is not recommended for new development. Please consider using [Verify V2](https://www.twilio.com/docs/verify/api)**.
216
82
 
83
+ ## Demo
217
84
 
218
- ## Contributing to authy
85
+ See the [`./examples`](./examples) directory for a demo CLI application that uses the Authy API.
219
86
 
87
+ ## Contributing
220
88
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
221
89
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
222
90
  * Fork the project.
223
91
  * Start a feature/bugfix branch.
224
92
  * Commit and push until you are happy with your contribution.
225
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
226
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
93
+ * Add tests.
94
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit.
95
+
96
+ ## Notice: Twilio Authy API’s Sandbox feature will stop working on Sep 30, 2021
97
+ Twilio is discontinuing the Authy API’s Sandbox, a feature that allows customers to run continuous integration tests against a mock Authy API for free. The Sandbox is no longer being maintained, so we will be taking the final deprecation step of shutting it down on September 30, 2021. The rest of the Authy API product will continue working as-is.
98
+
99
+ This repo previously used the sandbox API as part of the test suite, but that has been since removed.
100
+
101
+ You will only be affected if you are using the sandbox API in your own application or test suite.
102
+
103
+ For more information please read this article on [how we are discontinuing the Twilio Authy sandbox API](https://support.authy.com/hc/en-us/articles/1260803396889-Notice-Twilio-Authy-API-s-Sandbox-feature-will-stop-working-on-Sep-30-2021).
227
104
 
228
- Copyright
229
- ==
105
+ ## Copyright
230
106
 
231
- Copyright (c) 2011-2020 Authy Inc. See LICENSE.txt for
232
- further details.
107
+ Copyright (c) 2011-2021 Authy Inc. See [LICENSE](https://github.com/twilio/authy-ruby/blob/master/LICENSE.txt) for further details.
data/authy.gemspec CHANGED
@@ -9,12 +9,10 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Authy Inc"]
10
10
  s.email = ["support@authy.com"]
11
11
  s.homepage = "https://github.com/authy/authy-ruby"
12
- s.summary = %q{Ruby library to access Authy services}
13
- s.description = %q{Ruby library to access Authy services}
12
+ s.summary = %q{Deprecated: please see README for details}
13
+ s.description = %q{Ruby library to access Authy services. This gem is deprecated, please see the README for details.}
14
14
  s.license = 'MIT'
15
15
 
16
- s.rubyforge_project = "authy"
17
-
18
16
  s.files = `git ls-files`.split("\n")
19
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
data/examples/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "authy"
4
+ gem "sqlite3"
5
+ gem "activerecord"
6
+ gem "highline"
@@ -0,0 +1,48 @@
1
+ # Demo
2
+
3
+ In this `example` directory is a demo of using the Twilio Authy Two-Factor Authentication (2FA) API with the Authy gem.
4
+
5
+ ## How does it work?
6
+
7
+ The demo works on the command line and allows you to register a user in your Authy application, request a token for that user and verify a token for a user. Registered users and their authy_id token are stored in a local SQLite database.
8
+
9
+ ## How to use the demo
10
+
11
+ Change into the `examples` directory and install the dependencies with:
12
+
13
+ ```bash
14
+ bundle install
15
+ ```
16
+
17
+ Then, run the demo with:
18
+
19
+ ```bash
20
+ ./demo.rb
21
+ ```
22
+
23
+ You will be asked for your Authy API key then presented a list of options.
24
+
25
+ ```bash
26
+ $ ./demo.rb
27
+
28
+ Enter your Authy API Key (won't be displayed):
29
+ 1. Register a user
30
+ 2. Request token
31
+ 3. Verify token
32
+ What do you want to do?
33
+ ```
34
+
35
+ On the first run, choose to register a user. This will ask you for an email address, country code and phone number. With those details a user will be registered with your Authy application and stored in your local database.
36
+
37
+ Then you can run the application and either request a token, to have a token sent by SMS, or verify a token, you can use the token from an SMS or the Authy app to verify.
38
+
39
+ ### API keys
40
+
41
+ You will be asked for your Authy API key each time you run the demo. You can avoid this by [adding your Authy API key to your environment variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html).
42
+
43
+ ```
44
+ export AUTHY_API_KEY=ABC123xxxxx
45
+ ./demo.rb
46
+ ```
47
+
48
+ Check out the code in `./examples/demo.rb` to see how the API and this gem is used.
data/examples/demo.rb CHANGED
@@ -5,12 +5,11 @@ require 'sqlite3'
5
5
  require 'active_record'
6
6
  require 'highline/import' # gem install highline
7
7
 
8
- Authy.api_url = "http://sandbox-api.authy.com"
9
- Authy.api_key = "a1ffc30aa2d775c7ebebe45585727fe0"
8
+ trap("SIGINT") { exit! }
10
9
 
11
10
  # setup db
12
11
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "db")
13
- class AddUsers < ActiveRecord::Migration
12
+ class AddUsers < ActiveRecord::Migration[6.0]
14
13
  def self.up
15
14
  create_table :users do |t|
16
15
  t.string :email
@@ -28,11 +27,15 @@ class User < ActiveRecord::Base
28
27
  validates_uniqueness_of :email
29
28
  end
30
29
 
30
+ api_key = ENV["AUTHY_API_KEY"] || ask("Enter your Authy API Key (won't be displayed): "){ |q| q.echo = false }
31
+
32
+ Authy.api_url = "https://api.authy.com"
33
+ Authy.api_key = api_key
31
34
 
32
35
  choose do |menu|
33
- menu.prompt = "what do you want to do? "
36
+ menu.prompt = "What do you want to do? "
34
37
 
35
- menu.choice(:register) do
38
+ menu.choice("Register a user") do
36
39
  loop do
37
40
  email = ask("email: ")
38
41
  country_code = ask("country code: ")
@@ -55,9 +58,8 @@ choose do |menu|
55
58
  end
56
59
  end
57
60
 
58
- menu.choice(:login) do
61
+ menu.choice("Request token") do
59
62
  email = ask("email: ")
60
- token = ask("token: ")
61
63
 
62
64
  user = User.where(:email => email).first
63
65
  if !user
@@ -65,17 +67,18 @@ choose do |menu|
65
67
  return
66
68
  end
67
69
 
68
- # verify if the given token is correct. `force` makes it validate the code even if the user has not confirmed its account
69
- otp = Authy::API.verify(:id => user.authy_id, :token => token, :force => true)
70
+ # send sms to the user. `force` makes it send the sms even if the user uses a smartphone
71
+ # this api call will return an error if the account doesn't have the SMS addon enabled
72
+ response = Authy::API.request_sms(:id => user.authy_id, :force => true)
70
73
 
71
- if otp.ok?
72
- puts "Welcome back!"
74
+ if response.ok?
75
+ puts "Message was sent"
73
76
  else
74
- puts "Wrong email or token :("
77
+ puts "Failed to send message: #{response.errors.inspect}"
75
78
  end
76
79
  end
77
80
 
78
- menu.choice(:request_token) do
81
+ menu.choice("Verify token") do
79
82
  email = ask("email: ")
80
83
 
81
84
  user = User.where(:email => email).first
@@ -84,14 +87,15 @@ choose do |menu|
84
87
  return
85
88
  end
86
89
 
87
- # send sms to the user. `force` makes it send the sms even if the user uses a smartphone
88
- # this api call will return an error if the account doesn't have the SMS addon enabled
89
- response = Authy::API.request_sms(:id => user.authy_id, :force => true)
90
+ token = ask("token: ")
90
91
 
91
- if response.ok?
92
- puts "Message was sent"
92
+ # verify if the given token is correct. `force` makes it validate the code even if the user has not confirmed its account
93
+ otp = Authy::API.verify(:id => user.authy_id, :token => token, :force => true)
94
+
95
+ if otp.ok?
96
+ puts "Welcome back!"
93
97
  else
94
- puts "Failed to send message: #{response.errors.inspect}"
98
+ puts "Wrong email or token :("
95
99
  end
96
100
  end
97
101
  end