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 +4 -4
- data/.github/workflows/build.yml +21 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +1 -11
- data/LICENSE.txt +1 -1
- data/README.md +59 -184
- data/authy.gemspec +2 -4
- data/examples/Gemfile +6 -0
- data/examples/README.md +48 -0
- data/examples/demo.rb +23 -19
- data/lib/authy/api.rb +67 -61
- data/lib/authy/config.rb +8 -0
- data/lib/authy/onetouch.rb +1 -1
- data/lib/authy/phone_verification.rb +5 -2
- data/lib/authy/url_helpers.rb +0 -4
- data/lib/authy/version.rb +1 -1
- data/lib/authy.rb +2 -2
- data/spec/authy/api_spec.rb +388 -92
- data/spec/authy/config_spec.rb +21 -1
- data/spec/authy/onetouch_spec.rb +86 -30
- data/spec/authy/phone_verification_spec.rb +185 -54
- data/spec/authy/url_helpers_spec.rb +0 -12
- data/spec/spec_helper.rb +1 -2
- data/verify-legacy-v1.md +35 -0
- metadata +14 -17
- data/.travis.yml +0 -4
- data/Gemfile.lock +0 -118
- data/examples/pv-check.rb +0 -9
- data/examples/pv.rb +0 -12
- data/lib/authy/core_ext.rb +0 -26
- data/lib/authy/phone_intelligence.rb +0 -23
- data/spec/authy/phone_intelligence_spec.rb +0 -94
data/lib/authy/api.rb
CHANGED
@@ -1,21 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require "logger"
|
2
2
|
|
3
3
|
module Authy
|
4
|
-
|
5
|
-
AUTHY_LOGGER = Logger.new(STDOUT)
|
6
|
-
#
|
7
|
-
# Authy.api_key = 'foo'
|
8
|
-
# Authy.api_uri = 'http://test-authy-api.heroku.com/'
|
9
|
-
#
|
10
4
|
class API
|
11
|
-
USER_AGENT = "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
|
12
5
|
MIN_TOKEN_SIZE = 6
|
13
6
|
MAX_TOKEN_SIZE = 12
|
14
7
|
|
15
8
|
include Authy::URL
|
16
9
|
|
17
10
|
extend HTTPClient::IncludeClient
|
18
|
-
include_http_client
|
11
|
+
include_http_client
|
19
12
|
|
20
13
|
def self.register_user(attributes)
|
21
14
|
api_key = attributes.delete(:api_key) || Authy.api_key
|
@@ -26,7 +19,7 @@ module Authy
|
|
26
19
|
}
|
27
20
|
|
28
21
|
url = "#{Authy.api_uri}/protected/json/users/new"
|
29
|
-
response = http_client.post(url, :body => escape_query(params), :header => default_header(api_key: api_key))
|
22
|
+
response = http_client.post(url, :body => escape_query(params), :header => default_header(params: { api_key: api_key }))
|
30
23
|
|
31
24
|
Authy::User.new(response)
|
32
25
|
end
|
@@ -37,19 +30,18 @@ module Authy
|
|
37
30
|
# :force (true|false) force to check even if the cellphone is not confirmed
|
38
31
|
#
|
39
32
|
def self.verify(params)
|
40
|
-
token = params.delete(:token) || params.delete(
|
41
|
-
user_id = params.delete(:id) || params.delete(
|
33
|
+
token = params.delete(:token) || params.delete("token")
|
34
|
+
user_id = params.delete(:id) || params.delete("id")
|
42
35
|
|
43
|
-
return invalid_response(
|
44
|
-
return invalid_response(
|
36
|
+
return invalid_response("Token format is invalid") unless token_is_safe?(token)
|
37
|
+
return invalid_response("User id is invalid") unless is_digit?(user_id)
|
45
38
|
|
46
|
-
params[:force] = true if params[:force].nil? && params[
|
39
|
+
params[:force] = true if params[:force].nil? && params["force"].nil?
|
47
40
|
|
48
41
|
response = get_request("protected/json/verify/:token/:user_id", params.merge({
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
)
|
42
|
+
"token" => token,
|
43
|
+
"user_id" => user_id
|
44
|
+
}))
|
53
45
|
|
54
46
|
return verify_response(response) if response.ok?
|
55
47
|
return response
|
@@ -59,7 +51,7 @@ module Authy
|
|
59
51
|
# :id user id
|
60
52
|
# :force force sms
|
61
53
|
def self.request_sms(params)
|
62
|
-
user_id = params.delete(:id) || params.delete(
|
54
|
+
user_id = params.delete(:id) || params.delete("id")
|
63
55
|
|
64
56
|
get_request("protected/json/sms/:user_id", params.merge({"user_id" => user_id}))
|
65
57
|
end
|
@@ -69,14 +61,14 @@ module Authy
|
|
69
61
|
# :qr_size qr size
|
70
62
|
# :qr_label context for qr code
|
71
63
|
def self.request_qr_code(params)
|
72
|
-
user_id = params.delete(:id) || params.delete(
|
73
|
-
qr_size = params.delete(:qr_size) || params.delete(
|
74
|
-
qr_label = params.delete(:qr_label) || params.delete(
|
64
|
+
user_id = params.delete(:id) || params.delete("id")
|
65
|
+
qr_size = params.delete(:qr_size) || params.delete("qr_size") || 300
|
66
|
+
qr_label = params.delete(:qr_label) || params.delete("qr_label") || ""
|
75
67
|
|
76
|
-
return invalid_response(
|
77
|
-
return invalid_response(
|
68
|
+
return invalid_response("User id is invalid") unless is_digit?(user_id)
|
69
|
+
return invalid_response("Qr image size is invalid") unless is_digit?(qr_size)
|
78
70
|
|
79
|
-
response = post_request("protected/json/users/:user_id/secret"
|
71
|
+
response = post_request("protected/json/users/:user_id/secret", params.merge({
|
80
72
|
"user_id" => user_id,
|
81
73
|
"qr_size" => qr_size,
|
82
74
|
"label" => qr_label
|
@@ -87,19 +79,38 @@ module Authy
|
|
87
79
|
# :id user id
|
88
80
|
# :force force phone_call
|
89
81
|
def self.request_phone_call(params)
|
90
|
-
user_id = params.delete(:id) || params.delete(
|
82
|
+
user_id = params.delete(:id) || params.delete("id")
|
91
83
|
|
92
84
|
get_request("protected/json/call/:user_id", params.merge({"user_id" => user_id}))
|
93
85
|
end
|
94
86
|
|
95
87
|
# options:
|
96
88
|
# :id user id
|
97
|
-
def self.
|
89
|
+
def self.request_email(params)
|
90
|
+
user_id = params.delete(:id) || params.delete('id')
|
91
|
+
|
92
|
+
post_request("protected/json/email/:user_id", params.merge({"user_id" => user_id}))
|
93
|
+
end
|
94
|
+
|
95
|
+
# options:
|
96
|
+
# :id user id
|
97
|
+
# :email user's new email
|
98
|
+
def self.update_user(params)
|
98
99
|
user_id = params.delete(:id) || params.delete('id')
|
99
100
|
|
100
|
-
post_request("protected/json/users
|
101
|
+
post_request("protected/json/users/:user_id/update", params.merge({"user_id" => user_id}))
|
101
102
|
end
|
102
103
|
|
104
|
+
# options:
|
105
|
+
# :id user id
|
106
|
+
def self.delete_user(params)
|
107
|
+
user_id = params.delete(:id) || params.delete("id")
|
108
|
+
|
109
|
+
post_request("protected/json/users/delete/:user_id", params.merge({"user_id" => user_id}))
|
110
|
+
end
|
111
|
+
|
112
|
+
# options:
|
113
|
+
# :id user id
|
103
114
|
def self.user_status(params)
|
104
115
|
user_id = params.delete(:id) || params.delete("id")
|
105
116
|
get_request("protected/json/users/:user_id/status", params.merge({"user_id" => user_id}))
|
@@ -114,12 +125,12 @@ module Authy
|
|
114
125
|
state, error = validate_for_url(uri_params, params)
|
115
126
|
|
116
127
|
response = if state
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
128
|
+
url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
|
129
|
+
params = clean_uri_params(uri_params, params)
|
130
|
+
http_client.post(url, :body => escape_query(params), header: header_)
|
131
|
+
else
|
132
|
+
build_error_response(error)
|
133
|
+
end
|
123
134
|
Authy::Response.new(response)
|
124
135
|
end
|
125
136
|
|
@@ -129,24 +140,24 @@ module Authy
|
|
129
140
|
uri_params = keys_to_verify(uri, params)
|
130
141
|
state, error = validate_for_url(uri_params, params)
|
131
142
|
response = if state
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
143
|
+
url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
|
144
|
+
params = clean_uri_params(uri_params, params)
|
145
|
+
http_client.get(url, params, header_)
|
146
|
+
else
|
147
|
+
build_error_response(error)
|
148
|
+
end
|
138
149
|
Authy::Response.new(response)
|
139
150
|
end
|
140
151
|
|
141
152
|
def self.build_error_response(error = "blank uri param found")
|
142
153
|
OpenStruct.new({
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
}
|
154
|
+
"status" => 400,
|
155
|
+
"body" => {
|
156
|
+
"success" => false,
|
157
|
+
"message" => error,
|
158
|
+
"errors" => {
|
159
|
+
"message" => error,
|
160
|
+
},
|
150
161
|
}.to_json
|
151
162
|
})
|
152
163
|
end
|
@@ -159,31 +170,26 @@ module Authy
|
|
159
170
|
!!(/^\d+$/.match str.to_s)
|
160
171
|
end
|
161
172
|
|
162
|
-
def self.invalid_response(str="Invalid resonse")
|
173
|
+
def self.invalid_response(str = "Invalid resonse")
|
163
174
|
response = build_error_response(str)
|
164
175
|
return Authy::Response.new(response)
|
165
176
|
end
|
166
177
|
|
167
178
|
def self.verify_response(response)
|
168
|
-
return response if response[
|
169
|
-
response = build_error_response(
|
179
|
+
return response if response["token"] == "is valid"
|
180
|
+
response = build_error_response("Token is invalid")
|
170
181
|
return Authy::Response.new(response)
|
171
182
|
end
|
172
183
|
|
173
|
-
def self.default_header(
|
184
|
+
def self.default_header(params: {})
|
185
|
+
api_key = params.delete(:api_key) || params.delete("api_key")
|
186
|
+
|
174
187
|
header = {
|
175
|
-
"X-Authy-API-Key" => api_key || Authy.api_key
|
188
|
+
"X-Authy-API-Key" => api_key || Authy.api_key,
|
189
|
+
"User-Agent" => Authy.user_agent
|
176
190
|
}
|
177
191
|
|
178
|
-
api_key_ = params.delete(:api_key) || params.delete("api_key")
|
179
|
-
|
180
|
-
if api_key_ && api_key_.strip != ""
|
181
|
-
AUTHY_LOGGER.warn("[DEPRECATED]: The Authy API key should not be sent as a parameter. Please send the HTTP header 'X-Authy-API-Key' instead.")
|
182
|
-
header["X-Authy-API-Key"] = api_key_
|
183
|
-
end
|
184
|
-
|
185
192
|
return header
|
186
193
|
end
|
187
|
-
|
188
194
|
end
|
189
195
|
end
|
data/lib/authy/config.rb
CHANGED
@@ -17,5 +17,13 @@ module Authy
|
|
17
17
|
@api_uri || "https://api.authy.com"
|
18
18
|
end
|
19
19
|
alias :api_url :api_uri
|
20
|
+
|
21
|
+
def user_agent
|
22
|
+
@user_agent || "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_agent=(user_agent)
|
26
|
+
@user_agent = user_agent
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
data/lib/authy/onetouch.rb
CHANGED
@@ -6,8 +6,11 @@ module Authy
|
|
6
6
|
# :phone_number The persons phone number.
|
7
7
|
# :custom_code Pass along any generated custom code.
|
8
8
|
# :custom_message Custom Message.
|
9
|
+
# :code_length Length of code to be sent(4-10).
|
10
|
+
# :locale The language of the message received by user.
|
9
11
|
def self.start(params)
|
10
|
-
|
12
|
+
warn "Authy Phone Verification has been superseded by the Twilio Verify API. Check https://twil.io/verify-start-ruby to see how to start a verification with the Twilio Verify API."
|
13
|
+
params[:via] = "sms" unless %w(sms call).include?(params[:via])
|
11
14
|
|
12
15
|
post_request("protected/json/phones/verification/start", params)
|
13
16
|
end
|
@@ -17,8 +20,8 @@ module Authy
|
|
17
20
|
# :phone_number The persons phone number.
|
18
21
|
# :verification_code The verification code entered by the user.
|
19
22
|
def self.check(params)
|
23
|
+
warn "Authy Phone Verification has been superseded by the Twilio Verify API. Check https://twil.io/verify-check-ruby to see how to check a verification the Twilio Verify API."
|
20
24
|
get_request("protected/json/phones/verification/check", params)
|
21
25
|
end
|
22
|
-
|
23
26
|
end
|
24
27
|
end
|
data/lib/authy/url_helpers.rb
CHANGED
@@ -30,10 +30,6 @@ module Authy
|
|
30
30
|
[ true, ""]
|
31
31
|
end
|
32
32
|
|
33
|
-
def escape_for_url(field)
|
34
|
-
URI.escape(field.to_s.strip, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
35
|
-
end
|
36
|
-
|
37
33
|
def to_param(left, right)
|
38
34
|
HTTP::Message.escape(left) + '=' + HTTP::Message.escape(right.to_s)
|
39
35
|
end
|
data/lib/authy/version.rb
CHANGED
data/lib/authy.rb
CHANGED
@@ -6,11 +6,11 @@ require 'json'
|
|
6
6
|
|
7
7
|
require 'authy/version'
|
8
8
|
require 'authy/url_helpers'
|
9
|
-
require 'authy/core_ext'
|
10
9
|
require 'authy/response'
|
11
10
|
require 'authy/models/user'
|
12
11
|
require 'authy/config'
|
13
12
|
require 'authy/api'
|
14
|
-
require 'authy/phone_intelligence'
|
15
13
|
require 'authy/phone_verification'
|
16
14
|
require 'authy/onetouch'
|
15
|
+
|
16
|
+
warn "DEPRECATION WARNING: The authy-ruby library is no longer actively maintained. The Authy API is being replaced by the Twilio Verify API. Please see the README for more details."
|