api-auth 1.3.2 → 1.4.0
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/.rspec +2 -2
- data/.travis.yml +4 -0
- data/Appraisals +6 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile.lock +77 -44
- data/README.md +15 -8
- data/VERSION +1 -1
- data/api_auth.gemspec +4 -4
- data/gemfiles/rails_23.gemfile +1 -1
- data/gemfiles/rails_23.gemfile.lock +19 -11
- data/gemfiles/rails_30.gemfile +1 -1
- data/gemfiles/rails_30.gemfile.lock +19 -11
- data/gemfiles/rails_31.gemfile +1 -1
- data/gemfiles/rails_31.gemfile.lock +19 -11
- data/gemfiles/rails_32.gemfile +1 -1
- data/gemfiles/rails_32.gemfile.lock +19 -11
- data/gemfiles/rails_4.gemfile +1 -1
- data/gemfiles/rails_4.gemfile.lock +19 -11
- data/gemfiles/rails_41.gemfile +1 -1
- data/gemfiles/rails_41.gemfile.lock +19 -11
- data/gemfiles/rails_42.gemfile +9 -0
- data/gemfiles/rails_42.gemfile.lock +115 -0
- data/lib/api_auth/base.rb +37 -23
- data/lib/api_auth/headers.rb +23 -3
- data/lib/api_auth/request_drivers/action_controller.rb +4 -0
- data/lib/api_auth/request_drivers/curb.rb +4 -0
- data/lib/api_auth/request_drivers/faraday.rb +4 -0
- data/lib/api_auth/request_drivers/httpi.rb +5 -1
- data/lib/api_auth/request_drivers/net_http.rb +4 -0
- data/lib/api_auth/request_drivers/rack.rb +5 -1
- data/lib/api_auth/request_drivers/rest_client.rb +4 -0
- data/spec/api_auth_spec.rb +112 -628
- data/spec/headers_spec.rb +132 -289
- data/spec/helpers_spec.rb +2 -2
- data/spec/railtie_spec.rb +13 -8
- data/spec/request_drivers/action_controller_spec.rb +218 -0
- data/spec/request_drivers/action_dispatch_spec.rb +219 -0
- data/spec/request_drivers/curb_spec.rb +89 -0
- data/spec/request_drivers/faraday_spec.rb +243 -0
- data/spec/request_drivers/httpi_spec.rb +147 -0
- data/spec/request_drivers/net_http_spec.rb +185 -0
- data/spec/request_drivers/rack_spec.rb +288 -0
- data/spec/request_drivers/rest_client_spec.rb +311 -0
- metadata +44 -19
- data/spec/application_helper.rb +0 -2
- data/spec/test_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4f04ff0b0fdfdc276177e1a225239af93aff34
|
4
|
+
data.tar.gz: 490677e918c7928517f8cb1bb476c5c81a9ac176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd94a12c5eaaf7b76390fead34de8b6a60644656343b3a3aedbfff4fc1b5eea64777c258b20136a6d1ff3aa2bf0c071c007914c4ad958d2db5684f48cce23e08
|
7
|
+
data.tar.gz: 4ac0b39723cb446470b716d4cd8b06bc111bc88fd85fabf0c9e72a1300b6765c460463f038d9ed59f1d0c838bdcb5d103421e80cc833fba5e673bf43ffdea127
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
--colour
|
2
|
-
--format
|
3
|
-
--backtrace
|
2
|
+
--format doc
|
3
|
+
--backtrace
|
data/.travis.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
2
3
|
rvm:
|
3
4
|
- 1.8.7-p374
|
4
5
|
- 1.9.3
|
@@ -11,12 +12,15 @@ gemfile:
|
|
11
12
|
- gemfiles/rails_32.gemfile
|
12
13
|
- gemfiles/rails_4.gemfile
|
13
14
|
- gemfiles/rails_41.gemfile
|
15
|
+
- gemfiles/rails_42.gemfile
|
14
16
|
matrix:
|
15
17
|
exclude:
|
16
18
|
- rvm: 1.8.7-p374
|
17
19
|
gemfile: gemfiles/rails_4.gemfile
|
18
20
|
- rvm: 1.8.7-p374
|
19
21
|
gemfile: gemfiles/rails_41.gemfile
|
22
|
+
- rvm: 1.8.7-p374
|
23
|
+
gemfile: gemfiles/rails_42.gemfile
|
20
24
|
- rvm: 2.1.5
|
21
25
|
gemfile: gemfiles/rails_23.gemfile
|
22
26
|
- rvm: 2.1.5
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
# 1.4 (2015-12-16)
|
2
|
+
|
3
|
+
## IMPORTANT SECURITY FIX (with backwards compatible fallback)
|
4
|
+
|
5
|
+
This version introduces a security fix. In previous versions, the canonical
|
6
|
+
string does not include the http method used to make the request, this means
|
7
|
+
two requests that would otherwise be identical (such as a GET and DELETE)
|
8
|
+
would have the same signature allowing for a MITM to swap one method for
|
9
|
+
another.
|
10
|
+
|
11
|
+
In ApiAuth v1.4 `ApiAuth.authentic?` will allow for requests signed using either
|
12
|
+
the canonical string WITH the http method, or WITHOUT it. `ApiAuth.sign!` will,
|
13
|
+
by default, still sign the request using the canonical string without the
|
14
|
+
method. However, passing in the `:with_http_method => true` option into
|
15
|
+
`ApiAuth.sign?` will cause the request to use the http method as part of the
|
16
|
+
canonical string.
|
17
|
+
|
18
|
+
Example:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
ApiAuth.sign!(request, access_id, secret_key, {:with_http_method => true})
|
22
|
+
```
|
23
|
+
|
24
|
+
This allows for an upgrade strategy that would look like the following.
|
25
|
+
|
26
|
+
1. Update server side code to use ApiAuth v1.4
|
27
|
+
2. Update client side code to use ApiAuth v1.4
|
28
|
+
3. Update all client side code to sign with http method
|
29
|
+
4. Update server side code to ApiAuth v2.0 (removes the ability to authenticate without the http method)
|
30
|
+
5. Update all client side code to ApiAuth v2.0 (forces all signatures to contain the http method)
|
31
|
+
|
32
|
+
## Additional changes
|
33
|
+
|
34
|
+
- Performance enhancement: reduce allocation of Headers object (#81 pd)
|
35
|
+
- Performance enhancement: avoid reallocating static Regexps (#82 pd)
|
36
|
+
|
1
37
|
# 1.3.2 (2015-08-28)
|
2
38
|
- Fixed a bug where some client adapters didn't treat an empty path as
|
3
39
|
"/" in the canonical string (#75 managr)
|
data/Gemfile.lock
CHANGED
@@ -1,75 +1,105 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api-auth (1.
|
4
|
+
api-auth (1.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
9
|
+
actionpack (4.2.5)
|
10
|
+
actionview (= 4.2.5)
|
11
|
+
activesupport (= 4.2.5)
|
12
|
+
rack (~> 1.6)
|
13
|
+
rack-test (~> 0.6.2)
|
14
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
16
|
+
actionview (4.2.5)
|
17
|
+
activesupport (= 4.2.5)
|
18
|
+
builder (~> 3.1)
|
19
|
+
erubis (~> 2.7.0)
|
20
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
22
|
+
activemodel (4.2.5)
|
23
|
+
activesupport (= 4.2.5)
|
24
|
+
builder (~> 3.1)
|
25
|
+
activeresource (4.0.0)
|
26
|
+
activemodel (~> 4.0)
|
27
|
+
activesupport (~> 4.0)
|
28
|
+
rails-observers (~> 0.1.1)
|
29
|
+
activesupport (4.2.5)
|
30
|
+
i18n (~> 0.7)
|
31
|
+
json (~> 1.7, >= 1.7.7)
|
32
|
+
minitest (~> 5.1)
|
33
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
34
|
+
tzinfo (~> 1.1)
|
28
35
|
amatch (0.2.10)
|
29
36
|
tins (~> 0.3)
|
30
|
-
appraisal (
|
37
|
+
appraisal (2.1.0)
|
31
38
|
bundler
|
32
39
|
rake
|
33
|
-
|
40
|
+
thor (>= 0.14.0)
|
41
|
+
builder (3.2.2)
|
34
42
|
curb (0.8.6)
|
35
|
-
diff-lcs (1.
|
36
|
-
erubis (2.
|
37
|
-
abstract (>= 1.0.0)
|
43
|
+
diff-lcs (1.2.5)
|
44
|
+
erubis (2.7.0)
|
38
45
|
faraday (0.9.1)
|
39
46
|
multipart-post (>= 1.2, < 3)
|
40
47
|
httpi (2.1.0)
|
41
48
|
rack
|
42
49
|
rubyntlm (~> 0.3.2)
|
43
|
-
i18n (0.
|
50
|
+
i18n (0.7.0)
|
51
|
+
json (1.8.3)
|
52
|
+
loofah (2.0.3)
|
53
|
+
nokogiri (>= 1.5.9)
|
44
54
|
mime-types (1.17.2)
|
55
|
+
mini_portile (0.6.2)
|
56
|
+
minitest (5.8.2)
|
45
57
|
multipart-post (2.0.0)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
rack-test (0.
|
58
|
+
nokogiri (1.6.6.2)
|
59
|
+
mini_portile (~> 0.6.0)
|
60
|
+
rack (1.6.4)
|
61
|
+
rack-test (0.6.3)
|
50
62
|
rack (>= 1.0)
|
51
|
-
|
63
|
+
rails-deprecated_sanitizer (1.0.3)
|
64
|
+
activesupport (>= 4.2.0.alpha)
|
65
|
+
rails-dom-testing (1.0.7)
|
66
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
67
|
+
nokogiri (~> 1.6.0)
|
68
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
69
|
+
rails-html-sanitizer (1.0.2)
|
70
|
+
loofah (~> 2.0)
|
71
|
+
rails-observers (0.1.2)
|
72
|
+
activemodel (~> 4.0)
|
73
|
+
rake (10.4.2)
|
52
74
|
rest-client (1.6.7)
|
53
75
|
mime-types (>= 1.16)
|
54
|
-
rspec (
|
55
|
-
rspec-core (~>
|
56
|
-
rspec-expectations (~>
|
57
|
-
rspec-mocks (~>
|
58
|
-
rspec-core (
|
59
|
-
|
60
|
-
|
61
|
-
|
76
|
+
rspec (3.4.0)
|
77
|
+
rspec-core (~> 3.4.0)
|
78
|
+
rspec-expectations (~> 3.4.0)
|
79
|
+
rspec-mocks (~> 3.4.0)
|
80
|
+
rspec-core (3.4.0)
|
81
|
+
rspec-support (~> 3.4.0)
|
82
|
+
rspec-expectations (3.4.0)
|
83
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
84
|
+
rspec-support (~> 3.4.0)
|
85
|
+
rspec-mocks (3.4.0)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.4.0)
|
88
|
+
rspec-support (3.4.0)
|
62
89
|
rubyntlm (0.3.4)
|
90
|
+
thor (0.19.1)
|
91
|
+
thread_safe (0.3.5)
|
63
92
|
tins (0.5.5)
|
64
|
-
tzinfo (
|
93
|
+
tzinfo (1.2.2)
|
94
|
+
thread_safe (~> 0.1)
|
65
95
|
|
66
96
|
PLATFORMS
|
67
97
|
ruby
|
68
98
|
|
69
99
|
DEPENDENCIES
|
70
|
-
actionpack (
|
71
|
-
activeresource (~>
|
72
|
-
activesupport (
|
100
|
+
actionpack (> 2.3.2, < 5.0)
|
101
|
+
activeresource (~> 4.0)
|
102
|
+
activesupport (> 2.3.2, < 5.0)
|
73
103
|
amatch
|
74
104
|
api-auth!
|
75
105
|
appraisal
|
@@ -79,4 +109,7 @@ DEPENDENCIES
|
|
79
109
|
multipart-post (~> 2.0)
|
80
110
|
rake
|
81
111
|
rest-client (~> 1.6.0)
|
82
|
-
rspec (~>
|
112
|
+
rspec (~> 3.4)
|
113
|
+
|
114
|
+
BUNDLED WITH
|
115
|
+
1.10.6
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/mgomes/api_auth)
|
4
4
|
|
5
|
+
## IMPORTANT: See [CHANGELOG.md](/CHANGELOG.md) for security update information
|
6
|
+
|
5
7
|
Logins and passwords are for humans. Communication between applications need to
|
6
8
|
be protected through different means.
|
7
9
|
|
@@ -25,7 +27,7 @@ content-MD5 are not present, then a blank string is used in their place. If the
|
|
25
27
|
timestamp isn't present, a valid HTTP date is automatically added to the
|
26
28
|
request. The canonical string is computed as follows:
|
27
29
|
|
28
|
-
canonical_string = 'content-type,content-MD5,request URI,timestamp'
|
30
|
+
canonical_string = 'http method,content-type,content-MD5,request URI,timestamp'
|
29
31
|
|
30
32
|
2. This string is then used to create the signature which is a Base64 encoded
|
31
33
|
SHA1 HMAC, using the client's private secret key.
|
@@ -73,9 +75,7 @@ Here is the current list of supported request objects:
|
|
73
75
|
|
74
76
|
### HTTP Client Objects
|
75
77
|
|
76
|
-
Here's a sample implementation of signing a request created with RestClient.
|
77
|
-
more examples, please check out the ApiAuth Spec where every supported HTTP
|
78
|
-
client is tested.
|
78
|
+
Here's a sample implementation of signing a request created with RestClient.
|
79
79
|
|
80
80
|
Assuming you have a client access id and secret as follows:
|
81
81
|
|
@@ -107,6 +107,14 @@ request as one of the last steps in building the request to ensure the headers
|
|
107
107
|
don't change after the signing process which would cause the authentication
|
108
108
|
check to fail on the server side.
|
109
109
|
|
110
|
+
If you are signing a request for a driver that doesn't support automatic http
|
111
|
+
method detection (like Curb or httpi), you can pass the http method as an option
|
112
|
+
into the sign! method like so:
|
113
|
+
|
114
|
+
``` ruby
|
115
|
+
@signed_request = ApiAuth.sign!(@request, @access_id, @secret_key, :override_http_method => "PUT")
|
116
|
+
```
|
117
|
+
|
110
118
|
### ActiveResource Clients
|
111
119
|
|
112
120
|
ApiAuth can transparently protect your ActiveResource communications with a
|
@@ -160,16 +168,15 @@ whether or not the request is authentic. Typically, the access id for the client
|
|
160
168
|
will be their record's primary key in the DB that stores the record or some other
|
161
169
|
public unique identifier for the client.
|
162
170
|
|
163
|
-
Here's a sample method that can be used in a `
|
171
|
+
Here's a sample method that can be used in a `before_action` if your server is a
|
164
172
|
Rails app:
|
165
173
|
|
166
174
|
``` ruby
|
167
|
-
|
175
|
+
before_action :api_authenticate
|
168
176
|
|
169
177
|
def api_authenticate
|
170
178
|
@current_account = Account.find_by_access_id(ApiAuth.access_id(request))
|
171
|
-
|
172
|
-
false
|
179
|
+
head(:unauthorized) unless @current_account && ApiAuth.authentic?(request, @current_account.secret_key)
|
173
180
|
end
|
174
181
|
```
|
175
182
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/api_auth.gemspec
CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.add_development_dependency "appraisal"
|
14
14
|
s.add_development_dependency "rake"
|
15
15
|
s.add_development_dependency "amatch"
|
16
|
-
s.add_development_dependency "rspec", "~>
|
17
|
-
s.add_development_dependency "actionpack", "
|
18
|
-
s.add_development_dependency "activesupport", "
|
19
|
-
s.add_development_dependency "activeresource", "~>
|
16
|
+
s.add_development_dependency "rspec", "~> 3.4"
|
17
|
+
s.add_development_dependency "actionpack", "< 5.0", "> 2.3.2"
|
18
|
+
s.add_development_dependency "activesupport", "< 5.0", "> 2.3.2"
|
19
|
+
s.add_development_dependency "activeresource", "~> 4.0"
|
20
20
|
s.add_development_dependency "rest-client", "~> 1.6.0"
|
21
21
|
s.add_development_dependency "curb", "~> 0.8.1"
|
22
22
|
s.add_development_dependency "httpi"
|
data/gemfiles/rails_23.gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
api-auth (1.
|
4
|
+
api-auth (1.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
rake
|
20
20
|
thor (>= 0.14.0)
|
21
21
|
curb (0.8.6)
|
22
|
-
diff-lcs (1.
|
22
|
+
diff-lcs (1.2.5)
|
23
23
|
faraday (0.9.1)
|
24
24
|
multipart-post (>= 1.2, < 3)
|
25
25
|
httpi (2.1.0)
|
@@ -31,14 +31,19 @@ GEM
|
|
31
31
|
rake (10.3.1)
|
32
32
|
rest-client (1.6.7)
|
33
33
|
mime-types (>= 1.16)
|
34
|
-
rspec (
|
35
|
-
rspec-core (~>
|
36
|
-
rspec-expectations (~>
|
37
|
-
rspec-mocks (~>
|
38
|
-
rspec-core (
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
rspec (3.4.0)
|
35
|
+
rspec-core (~> 3.4.0)
|
36
|
+
rspec-expectations (~> 3.4.0)
|
37
|
+
rspec-mocks (~> 3.4.0)
|
38
|
+
rspec-core (3.4.0)
|
39
|
+
rspec-support (~> 3.4.0)
|
40
|
+
rspec-expectations (3.4.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.4.0)
|
43
|
+
rspec-mocks (3.4.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.4.0)
|
46
|
+
rspec-support (3.4.0)
|
42
47
|
rubyntlm (0.3.4)
|
43
48
|
thor (0.19.1)
|
44
49
|
tins (1.3.0)
|
@@ -59,4 +64,7 @@ DEPENDENCIES
|
|
59
64
|
multipart-post (~> 2.0)
|
60
65
|
rake
|
61
66
|
rest-client (~> 1.6.0)
|
62
|
-
rspec (~>
|
67
|
+
rspec (~> 3.4)
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.10.6
|
data/gemfiles/rails_30.gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../
|
3
3
|
specs:
|
4
|
-
api-auth (1.
|
4
|
+
api-auth (1.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
thor (>= 0.14.0)
|
34
34
|
builder (2.1.2)
|
35
35
|
curb (0.8.6)
|
36
|
-
diff-lcs (1.
|
36
|
+
diff-lcs (1.2.5)
|
37
37
|
erubis (2.6.6)
|
38
38
|
abstract (>= 1.0.0)
|
39
39
|
faraday (0.9.1)
|
@@ -52,14 +52,19 @@ GEM
|
|
52
52
|
rake (10.3.1)
|
53
53
|
rest-client (1.6.7)
|
54
54
|
mime-types (>= 1.16)
|
55
|
-
rspec (
|
56
|
-
rspec-core (~>
|
57
|
-
rspec-expectations (~>
|
58
|
-
rspec-mocks (~>
|
59
|
-
rspec-core (
|
60
|
-
|
61
|
-
|
62
|
-
|
55
|
+
rspec (3.4.0)
|
56
|
+
rspec-core (~> 3.4.0)
|
57
|
+
rspec-expectations (~> 3.4.0)
|
58
|
+
rspec-mocks (~> 3.4.0)
|
59
|
+
rspec-core (3.4.0)
|
60
|
+
rspec-support (~> 3.4.0)
|
61
|
+
rspec-expectations (3.4.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.4.0)
|
64
|
+
rspec-mocks (3.4.0)
|
65
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
66
|
+
rspec-support (~> 3.4.0)
|
67
|
+
rspec-support (3.4.0)
|
63
68
|
rubyntlm (0.3.4)
|
64
69
|
thor (0.19.1)
|
65
70
|
tins (1.3.0)
|
@@ -81,4 +86,7 @@ DEPENDENCIES
|
|
81
86
|
multipart-post (~> 2.0)
|
82
87
|
rake
|
83
88
|
rest-client (~> 1.6.0)
|
84
|
-
rspec (~>
|
89
|
+
rspec (~> 3.4)
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
1.10.6
|