authy 2.7.2 → 2.7.3

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
- SHA1:
3
- metadata.gz: 8113421bc21b13bc9ad8d67d40f0396448d3950f
4
- data.tar.gz: e6d280e4e5e44a8a507531961d07c5e47199a122
2
+ SHA256:
3
+ metadata.gz: e5538f6f51f1db240a5c94c81aa1705cc3754e8abfeeb2bbb1dce5427211d361
4
+ data.tar.gz: 16752c3c96190eca0d25b862a44e815ea2ebc308d46de30933e1f6c9a089457d
5
5
  SHA512:
6
- metadata.gz: 94643682f6f44bbbaab85beb4efc63b0a2c49c383571fc904b078d1e46f5c3e6e1cc96278366089a1a9bc3c7d049da1b81800f299ac6dd4f8b21e93cc3d53026
7
- data.tar.gz: 4cd4391e4747294e2d66ea6aa93e55c27f2102f13d0ebbdef4c6240ecd4e20d922ec2bd7b139ce32eb8a99ff8864bfdde89fd98350aeeb4a8de7fb482c6ee3ef
6
+ metadata.gz: 6da72901a00717a60459ab310893e79c25f53f6633ed9734e8836e8a0ebbc310fa449f4ba79b08d879780058c8c0362c737af9b73e488db5aeb38a1210c7efbc
7
+ data.tar.gz: 885217cfd29aed61cbfb98644f0b38f2838e063c2535dc59cdf074b2ea0c8dbb5142921cfb77ac1d490b8aaaf8284a2e8a7781f37c939b52d4c6242f60cfe97d
data/README.md CHANGED
@@ -8,7 +8,7 @@ Ruby library to access the Authy API
8
8
  require 'authy'
9
9
 
10
10
  Authy.api_key = 'your-api-key'
11
- Authy.api_uri = 'https://api.authy.com/'
11
+ Authy.api_uri = 'https://api.authy.com'
12
12
  ```
13
13
 
14
14
  Using Ruby on Rails? _Put this in **config/initializers** and create a new file called **authy.rb**._
@@ -83,6 +83,14 @@ the SMS pass force=true as an option
83
83
  response = Authy::API.request_sms(:id => user.authy_id, :force => true)
84
84
  ```
85
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
+
86
94
  ## Requesting token via a phone call
87
95
 
88
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.
@@ -104,6 +112,22 @@ This call will be ignored if the user is using the Authy Mobile App. If you ensu
104
112
  response = Authy::API.request_phone_call(:id => user.authy_id, :force => true)
105
113
  ```
106
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
+
107
131
  ## Deleting users
108
132
 
109
133
  `Authy::API.delete_user` takes the authy_id of the user that you want to remove from your app.
@@ -138,7 +162,7 @@ This call will be ignored if the user is using the Authy Mobile App. If you ensu
138
162
 
139
163
  ### Starting a phone verification
140
164
 
141
- `Authy::PhoneVerification.start` takes a country code, phone number and a method (sms or call) to deliver the code.
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
142
166
 
143
167
  ```ruby
144
168
  response = Authy::PhoneVerification.start(via: "sms", country_code: 1, phone_number: "111-111-1111")
@@ -0,0 +1,9 @@
1
+ require 'authy' # gem install authy
2
+
3
+ Authy.api_url = "https://api.authy.com"
4
+ Authy.api_key = "[YOUR_API_KEY]"
5
+
6
+ response = Authy::PhoneVerification.check(verification_code: "1234", country_code: [YOUR_COUNTRY_CODE], phone_number: "[YOUR_PHONE_NUMBER]")
7
+ if response.ok?
8
+ # verification was started
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'authy' # gem install authy
2
+
3
+ Authy.api_url = "https://api.authy.com"
4
+ Authy.api_key = "[YOUR_API_KEY]"
5
+
6
+ # Custom Code example
7
+ # response = Authy::PhoneVerification.start(via: "sms", country_code: 1, phone_number: "[YOUR_NUMBER]", custom_code: "1234")
8
+
9
+ response = Authy::PhoneVerification.start(via: "sms", country_code: [YOUR_COUNTRY_CODE], phone_number: "[YOUR_PHONE_NUMBER]")
10
+ if response.ok?
11
+ # verification was started
12
+ end
@@ -64,6 +64,25 @@ module Authy
64
64
  get_request("protected/json/sms/:user_id", params.merge({"user_id" => user_id}))
65
65
  end
66
66
 
67
+ # options:
68
+ # :id user id
69
+ # :qr_size qr size
70
+ # :qr_label context for qr code
71
+ def self.request_qr_code(params)
72
+ user_id = params.delete(:id) || params.delete('id')
73
+ qr_size = params.delete(:qr_size) || params.delete('qr_size') || 300
74
+ qr_label = params.delete(:qr_label) || params.delete('qr_label') || ""
75
+
76
+ return invalid_response('User id is invalid') unless is_digit?(user_id)
77
+ return invalid_response('Qr image size is invalid') unless is_digit?(qr_size)
78
+
79
+ response = post_request("protected/json/users/:user_id/secret" ,params.merge({
80
+ "user_id" => user_id,
81
+ "qr_size" => qr_size,
82
+ "label" => qr_label
83
+ }))
84
+ end
85
+
67
86
  # options:
68
87
  # :id user id
69
88
  # :force force phone_call
@@ -4,6 +4,8 @@ module Authy
4
4
  # :via (sms|call)
5
5
  # :country_code Numeric calling country code of the country.
6
6
  # :phone_number The persons phone number.
7
+ # :custom_code Pass along any generated custom code.
8
+ # :custom_message Custom Message.
7
9
  def self.start(params)
8
10
  params[:via] = "sms" unless %w(sms, call).include?(params[:via])
9
11
 
@@ -1,3 +1,3 @@
1
1
  module Authy
2
- VERSION = "2.7.2"
2
+ VERSION = "2.7.3"
3
3
  end
@@ -121,6 +121,37 @@ describe "Authy::API" do
121
121
  end
122
122
  end
123
123
 
124
+ describe "requesting qr code for other authenticator apps" do
125
+ before do
126
+ @user = Authy::API.register_user(email: generate_email, cellphone: generate_cellphone, country_code: 1)
127
+ expect(@user).to be_ok
128
+ end
129
+
130
+ it "should request qrcode" do
131
+ url = "#{Authy.api_uri}/protected/json/users/#{Authy::API.escape_for_url(@user.id)}/secret"
132
+ expect_any_instance_of(HTTPClient).to receive(:request).with(:post, url, body: "qr_size=300&label=example+app+name", header: {"X-Authy-API-Key" => Authy.api_key}) { double(ok?: true, body: "", status: 200) }
133
+ response = Authy::API.send("request_qr_code", id: @user.id, qr_size: 300, qr_label: "example app name")
134
+ expect(response).to be_ok
135
+ end
136
+
137
+
138
+ context "user id is not a number" do
139
+ it "should not be ok" do
140
+ response = Authy::API.send("request_qr_code", id: "tony")
141
+ expect(response.errors['message']).to eq "User id is invalid"
142
+ expect(response).to_not be_ok
143
+ end
144
+ end
145
+
146
+ context "qr size is not a number" do
147
+ it "should return the right error" do
148
+ response = Authy::API.send("request_qr_code", id: @user.id, qr_size: "notanumber")
149
+ expect(response.errors['message']).to eq "Qr image size is invalid"
150
+ expect(response).to_not be_ok
151
+ end
152
+ end
153
+ end
154
+
124
155
  ["sms", "phone_call"].each do |kind|
125
156
  title = kind.upcase
126
157
  describe "Requesting #{title}" do
@@ -53,6 +53,20 @@ describe "Authy::PhoneVerification" do
53
53
  end
54
54
  end
55
55
 
56
+ describe 'Check that a custom code request' do
57
+ it "should return an error if not enabled" do
58
+ pending("API is not returning expected response in this case. The test phone number is invalid")
59
+
60
+ response = Authy::PhoneVerification.start(
61
+ country_code: "1",
62
+ phone_number: "111-111-1111",
63
+ custom_code: "1234"
64
+ )
65
+ expect(response).not_to be_ok
66
+ expect(response.message).to eq("Phone verification couldn't be created: custom codes are not allowed.")
67
+ end
68
+ end
69
+
56
70
  describe "Check the verification code" do
57
71
  it "should return success true if code is correct" do
58
72
  pending("API is not returning expected response in this case. The test phone number is invalid.")
@@ -93,4 +107,5 @@ describe "Authy::PhoneVerification" do
93
107
  expect(response.message).to eq('Phone number is invalid')
94
108
  end
95
109
  end
110
+
96
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.2
4
+ version: 2.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authy Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -142,6 +142,8 @@ files:
142
142
  - authy.gemspec
143
143
  - bin/authy-api-console
144
144
  - examples/demo.rb
145
+ - examples/pv-check.rb
146
+ - examples/pv.rb
145
147
  - lib/authy.rb
146
148
  - lib/authy/api.rb
147
149
  - lib/authy/config.rb
@@ -181,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
183
  version: '0'
182
184
  requirements: []
183
185
  rubyforge_project: authy
184
- rubygems_version: 2.5.2.1
186
+ rubygems_version: 2.7.6
185
187
  signing_key:
186
188
  specification_version: 4
187
189
  summary: Ruby library to access Authy services