authy 2.7.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/authy/api.rb +28 -5
- data/lib/authy/version.rb +1 -1
- data/spec/authy/api_spec.rb +13 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb9d7de576c3afc925818fc8b89d5e67aac65fa9
|
4
|
+
data.tar.gz: 6a5313143bd01165c1b7ab33553b77a7ade3867b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a16398319ebcc4c88f2c1622a7d12c45b0528ccc1bbfe8570894dcc34340e77288d74cb94631d1293a9920dee3b2980015503364b4359b341f8db086739e707
|
7
|
+
data.tar.gz: aadec96c432b3454d8a325c5476f3c87d8799611fa9416e84306a7cf634bda789e44c4590b1e023fdecece709c4ca70db81c740e9d379e7829341d9025b889bc
|
data/lib/authy/api.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module Authy
|
4
|
+
|
5
|
+
AUTHY_LOGGER = Logger.new(STDOUT)
|
2
6
|
#
|
3
7
|
# Authy.api_key = 'foo'
|
4
8
|
# Authy.api_uri = 'http://test-authy-api.heroku.com/'
|
@@ -14,16 +18,15 @@ module Authy
|
|
14
18
|
include_http_client(agent_name: USER_AGENT)
|
15
19
|
|
16
20
|
def self.register_user(attributes)
|
17
|
-
api_key = attributes.delete(:api_key)
|
21
|
+
api_key = attributes.delete(:api_key) || Authy.api_key
|
18
22
|
send_install_link_via_sms = attributes.delete(:send_install_link_via_sms) { true }
|
19
23
|
params = {
|
20
24
|
:user => attributes,
|
21
|
-
:api_key => api_key || Authy.api_key,
|
22
25
|
:send_install_link_via_sms => send_install_link_via_sms
|
23
26
|
}
|
24
27
|
|
25
28
|
url = "#{Authy.api_uri}/protected/json/users/new"
|
26
|
-
response = http_client.post(url, :body => escape_query(params))
|
29
|
+
response = http_client.post(url, :body => escape_query(params), :header => default_header(api_key: api_key))
|
27
30
|
|
28
31
|
Authy::User.new(response)
|
29
32
|
end
|
@@ -86,13 +89,15 @@ module Authy
|
|
86
89
|
private
|
87
90
|
|
88
91
|
def self.post_request(uri, params = {})
|
92
|
+
header_ = default_header(params: params)
|
93
|
+
|
89
94
|
uri_params = keys_to_verify(uri, params)
|
90
95
|
state, error = validate_for_url(uri_params, params)
|
91
96
|
|
92
97
|
response = if state
|
93
98
|
url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
|
94
99
|
params = clean_uri_params(uri_params, params)
|
95
|
-
http_client.post(url, :body => escape_query(
|
100
|
+
http_client.post(url, :body => escape_query(params), header: header_)
|
96
101
|
else
|
97
102
|
build_error_response(error)
|
98
103
|
end
|
@@ -100,12 +105,14 @@ module Authy
|
|
100
105
|
end
|
101
106
|
|
102
107
|
def self.get_request(uri, params = {})
|
108
|
+
header_ = default_header(params: params)
|
109
|
+
|
103
110
|
uri_params = keys_to_verify(uri, params)
|
104
111
|
state, error = validate_for_url(uri_params, params)
|
105
112
|
response = if state
|
106
113
|
url = "#{Authy.api_uri}/#{eval_uri(uri, params)}"
|
107
114
|
params = clean_uri_params(uri_params, params)
|
108
|
-
http_client.get(url,
|
115
|
+
http_client.get(url, params, header_)
|
109
116
|
else
|
110
117
|
build_error_response(error)
|
111
118
|
end
|
@@ -143,5 +150,21 @@ module Authy
|
|
143
150
|
response = build_error_response('Token is invalid')
|
144
151
|
return Authy::Response.new(response)
|
145
152
|
end
|
153
|
+
|
154
|
+
def self.default_header(api_key: nil, params: {})
|
155
|
+
header = {
|
156
|
+
"X-Authy-API-Key" => api_key || Authy.api_key
|
157
|
+
}
|
158
|
+
|
159
|
+
api_key_ = params.delete(:api_key) || params.delete("api_key")
|
160
|
+
|
161
|
+
if api_key_ && api_key_.strip != ""
|
162
|
+
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.")
|
163
|
+
header["X-Authy-API-Key"] = api_key_
|
164
|
+
end
|
165
|
+
|
166
|
+
return header
|
167
|
+
end
|
168
|
+
|
146
169
|
end
|
147
170
|
end
|
data/lib/authy/version.rb
CHANGED
data/spec/authy/api_spec.rb
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Authy::API" do
|
4
|
+
|
5
|
+
describe "request headers" do
|
6
|
+
|
7
|
+
it "contains api key in header" do
|
8
|
+
url = "protected/json/foo/2"
|
9
|
+
|
10
|
+
HTTPClient.any_instance.should_receive(:request).twice.with( any_args, hash_including(:header=> { "X-Authy-API-Key" => Authy.api_key }) ) { double(:ok? => true, :body => "", :status => 200) }
|
11
|
+
response = Authy::API.get_request(url, {})
|
12
|
+
response = Authy::API.post_request(url, {})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
4
16
|
describe "Registering users" do
|
5
17
|
|
6
18
|
it "should find or create a user" do
|
@@ -122,7 +134,7 @@ describe "Authy::API" do
|
|
122
134
|
it "should request a #{title} token" do
|
123
135
|
uri_param = kind == "phone_call" ? "call" : kind
|
124
136
|
url = "#{Authy.api_uri}/protected/json/#{uri_param}/#{Authy::API.escape_for_url(@user.id)}"
|
125
|
-
HTTPClient.any_instance.should_receive(:request).with(:get, url, {:query=>{:
|
137
|
+
HTTPClient.any_instance.should_receive(:request).with(:get, url, {:query=>{}, :header=>{ "X-Authy-API-Key" => Authy.api_key }, :follow_redirect=>nil}) { double(:ok? => true, :body => "", :status => 200) }
|
126
138
|
response = Authy::API.send("request_#{kind}", :id => @user.id)
|
127
139
|
response.should be_ok
|
128
140
|
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.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Authy Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project: authy
|
184
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.6.0
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: Ruby library to access Authy services
|