authy 2.7.0 → 2.7.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
  SHA1:
3
- metadata.gz: 9a7a9d75bf6b712ad35e60eea16462aa4d97bea5
4
- data.tar.gz: f56ddadf3459645a46cb2d2b13ad83fa1adf3a87
3
+ metadata.gz: bb9d7de576c3afc925818fc8b89d5e67aac65fa9
4
+ data.tar.gz: 6a5313143bd01165c1b7ab33553b77a7ade3867b
5
5
  SHA512:
6
- metadata.gz: a57a8444a61350a4568af7cff50009a2798e3d0cd69798b133085e45ab179121f8c1b304a160d62300b2812fe80b04478ea55c01f310fe21de24a51ab5e2aa2a
7
- data.tar.gz: 5e243df783f49669dce867aa303cb5e75009e751748a862a08862b67061fbff211eca00c4f1db3854c45f39ec7b08dd6ddff47f1062d2dedb64f38bb5f0e691d
6
+ metadata.gz: 7a16398319ebcc4c88f2c1622a7d12c45b0528ccc1bbfe8570894dcc34340e77288d74cb94631d1293a9920dee3b2980015503364b4359b341f8db086739e707
7
+ data.tar.gz: aadec96c432b3454d8a325c5476f3c87d8799611fa9416e84306a7cf634bda789e44c4590b1e023fdecece709c4ca70db81c740e9d379e7829341d9025b889bc
@@ -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({:api_key => Authy.api_key}.merge(params)))
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, {:api_key => Authy.api_key}.merge(params))
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
@@ -1,3 +1,3 @@
1
1
  module Authy
2
- VERSION = "2.7.0"
2
+ VERSION = "2.7.1"
3
3
  end
@@ -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=>{:api_key=> Authy.api_key}, :header=>nil, :follow_redirect=>nil}) { double(:ok? => true, :body => "", :status => 200) }
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.0
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-07-15 00:00:00.000000000 Z
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.4.6
184
+ rubygems_version: 2.6.0
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Ruby library to access Authy services