rack-jwt-auth 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/rack/jwt/auth/auth_token.rb +1 -1
- data/lib/rack/jwt/auth/authenticate.rb +4 -0
- data/lib/rack/jwt/auth/version.rb +1 -1
- data/rack-jwt-auth.gemspec +1 -1
- data/spec/auth_token_spec.rb +1 -1
- data/spec/authenticate_options_spec.rb +29 -20
- data/spec/authenticate_spec.rb +1 -1
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ee21c6c6d0ef268e67ba2506cde5efbacf6d03b
|
4
|
+
data.tar.gz: c76f6563a3a8e902496c5f755229ce66c258a25d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5b06936e30e0a9a766d140abe1b2a493f0b527e90c5b2011c9997981e7a3b57b0ff7ac5f8329acc2e73960c013c93809b3f8328ea1e14a269c2b91eac9c05c
|
7
|
+
data.tar.gz: 4fd9a4cc92905e6060f9d73cca50acf5979eeda77ede053acf43e78bbece7d80e1cc1cdf9051a4a3f1dd6f914b461d95cfaa7653d00efb3a4dece63b04b24351
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [2.0.0]
|
4
|
+
### Changed
|
5
|
+
- compatibility with JWT library version 2.0. This library covers an important security vulnerability,
|
6
|
+
see here: https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries. The middleware now requires
|
7
|
+
algorithm parameter to be used when decoding incoming tokens. See spec/authenticate_options_spec.rb for examples.
|
@@ -23,6 +23,10 @@ module Rack
|
|
23
23
|
|
24
24
|
raise 'Secret must be provided' if opts[:secret].nil?
|
25
25
|
|
26
|
+
# @see https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
|
27
|
+
# @see https://github.com/jwt/ruby-jwt/pull/184
|
28
|
+
raise 'Algorithm must be provided for security reason' if opts[:algorithm].nil?
|
29
|
+
|
26
30
|
@secret = opts[:secret]
|
27
31
|
|
28
32
|
@authenticated_routes = compile_paths(opts[:only])
|
data/rack-jwt-auth.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "jwt", "
|
21
|
+
spec.add_dependency "jwt", "~> 2.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.3"
|
data/spec/auth_token_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe Rack::Jwt::Auth::AuthToken do
|
|
19
19
|
|
20
20
|
it 'checks if the provided token is valid' do
|
21
21
|
token = subject.issue_token(data, secret)
|
22
|
-
payload = subject.valid?(token, secret)
|
22
|
+
payload = subject.valid?(token, secret, { algorithm: 'HS256'})
|
23
23
|
|
24
24
|
meta, data = payload
|
25
25
|
|
@@ -3,30 +3,36 @@ require 'spec_helper'
|
|
3
3
|
describe Rack::Jwt::Auth::Authenticate do
|
4
4
|
include Rack::Test::Methods
|
5
5
|
|
6
|
-
let(:issuer) {
|
6
|
+
let(:issuer) {Rack::Jwt::Auth::AuthToken}
|
7
7
|
|
8
8
|
context "Except routes" do
|
9
9
|
|
10
10
|
let(:app) do
|
11
|
-
main_app = lambda {
|
12
|
-
Rack::Jwt::Auth::Authenticate.new(
|
11
|
+
main_app = lambda {|env| [200, env, ['Hello']]}
|
12
|
+
Rack::Jwt::Auth::Authenticate.new(
|
13
|
+
main_app,
|
14
|
+
{
|
15
|
+
except: ['/not_authenticated', '/not_authenticated/*'],
|
16
|
+
secret: 'supertestsecret',
|
17
|
+
algorithm: 'HS256'
|
18
|
+
})
|
13
19
|
end
|
14
20
|
|
15
21
|
it 'returns 200 ok if the request is for a route that is not authenticated' do
|
16
22
|
get('/not_authenticated')
|
17
23
|
|
18
24
|
expect(last_response.status).to eql(200)
|
19
|
-
expect(last_response.body).to
|
25
|
+
expect(last_response.body).to eql('Hello')
|
20
26
|
|
21
27
|
get('/not_authenticated/other')
|
22
28
|
|
23
29
|
expect(last_response.status).to eql(200)
|
24
|
-
expect(last_response.body).to
|
30
|
+
expect(last_response.body).to eql('Hello')
|
25
31
|
|
26
32
|
get('/not_authenticated/other/test')
|
27
33
|
|
28
34
|
expect(last_response.status).to eql(200)
|
29
|
-
expect(last_response.body).to
|
35
|
+
expect(last_response.body).to eql('Hello')
|
30
36
|
end
|
31
37
|
|
32
38
|
it 'returns 401 ok if the request is for a route that is authenticated' do
|
@@ -45,25 +51,27 @@ describe Rack::Jwt::Auth::Authenticate do
|
|
45
51
|
context "Only routes" do
|
46
52
|
|
47
53
|
let(:app) do
|
48
|
-
main_app = lambda {
|
49
|
-
Rack::Jwt::Auth::Authenticate.new(main_app, {
|
54
|
+
main_app = lambda {|env| [200, env, ['Hello']]}
|
55
|
+
Rack::Jwt::Auth::Authenticate.new(main_app, {
|
56
|
+
only: ['/authenticated', '/authenticated/*'], secret: 'supertestsecret', algorithm: 'HS256'
|
57
|
+
})
|
50
58
|
end
|
51
59
|
|
52
60
|
it 'returns 200 ok if the request is for a route that is not authenticated' do
|
53
61
|
get('/not_authenticated')
|
54
62
|
|
55
63
|
expect(last_response.status).to eql(200)
|
56
|
-
expect(last_response.body).to
|
64
|
+
expect(last_response.body).to eql('Hello')
|
57
65
|
|
58
66
|
get('/not_authenticated/other')
|
59
67
|
|
60
68
|
expect(last_response.status).to eql(200)
|
61
|
-
expect(last_response.body).to
|
69
|
+
expect(last_response.body).to eql('Hello')
|
62
70
|
|
63
71
|
get('/not_authenticated/other/test')
|
64
72
|
|
65
73
|
expect(last_response.status).to eql(200)
|
66
|
-
expect(last_response.body).to
|
74
|
+
expect(last_response.body).to eql('Hello')
|
67
75
|
end
|
68
76
|
|
69
77
|
it 'returns 401 ok if the request is for a route that is authenticated' do
|
@@ -82,25 +90,26 @@ describe Rack::Jwt::Auth::Authenticate do
|
|
82
90
|
context "Only with except routes" do
|
83
91
|
|
84
92
|
let(:app) do
|
85
|
-
main_app = lambda {
|
86
|
-
Rack::Jwt::Auth::Authenticate.new(main_app, {only: ['/authenticated', '/authenticated/*'], secret: 'supertestsecret'
|
93
|
+
main_app = lambda {|env| [200, env, ['Hello']]}
|
94
|
+
Rack::Jwt::Auth::Authenticate.new(main_app, {only: ['/authenticated', '/authenticated/*'], secret: 'supertestsecret',
|
95
|
+
algorithm: 'HS256'})
|
87
96
|
end
|
88
97
|
|
89
98
|
it 'returns 200 ok if the request is for a route that is not authenticated' do
|
90
99
|
get('/not_authenticated')
|
91
100
|
|
92
101
|
expect(last_response.status).to eql(200)
|
93
|
-
expect(last_response.body).to
|
102
|
+
expect(last_response.body).to eql('Hello')
|
94
103
|
|
95
104
|
get('/not_authenticated/other')
|
96
105
|
|
97
106
|
expect(last_response.status).to eql(200)
|
98
|
-
expect(last_response.body).to
|
107
|
+
expect(last_response.body).to eql('Hello')
|
99
108
|
|
100
109
|
get('/not_authenticated/other/test')
|
101
110
|
|
102
111
|
expect(last_response.status).to eql(200)
|
103
|
-
expect(last_response.body).to
|
112
|
+
expect(last_response.body).to eql('Hello')
|
104
113
|
end
|
105
114
|
|
106
115
|
it 'returns 401 ok if the request is for a route that is authenticated' do
|
@@ -117,10 +126,10 @@ describe Rack::Jwt::Auth::Authenticate do
|
|
117
126
|
end
|
118
127
|
|
119
128
|
context "with options for decode" do
|
120
|
-
let(:secret) {
|
129
|
+
let(:secret) {'supertestsecret'}
|
121
130
|
let(:app) do
|
122
|
-
main_app = lambda {
|
123
|
-
described_class.new(main_app, {
|
131
|
+
main_app = lambda {|env| [200, env, ['Hello']]}
|
132
|
+
described_class.new(main_app, {secret: secret, algorithm: 'RS256'})
|
124
133
|
end
|
125
134
|
|
126
135
|
it 'calls AuthToken.valid? with decode options' do
|
@@ -129,7 +138,7 @@ describe Rack::Jwt::Auth::Authenticate do
|
|
129
138
|
get('/', {}, {'HTTP_AUTHORIZATION' => "Bearer #{token}"})
|
130
139
|
|
131
140
|
expect(Rack::Jwt::Auth::AuthToken).to have_received(:valid?)
|
132
|
-
|
141
|
+
.with(token, secret, {algorithm: 'RS256'})
|
133
142
|
end
|
134
143
|
end
|
135
144
|
|
data/spec/authenticate_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Rack::Jwt::Auth::Authenticate do
|
|
7
7
|
|
8
8
|
let(:app) do
|
9
9
|
main_app = lambda { |env| [200, env, ['Hello']] }
|
10
|
-
Rack::Jwt::Auth::Authenticate.new(main_app, {secret: 'supertestsecret'})
|
10
|
+
Rack::Jwt::Auth::Authenticate.new(main_app, {secret: 'supertestsecret', algorithm: 'HS256'})
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'raises an exception if no secret if provided' do
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-jwt-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Almeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0.6'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.6'
|
83
83
|
description: Rack jwt auth middleware
|
@@ -87,7 +87,8 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
91
|
+
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|
@@ -111,17 +112,17 @@ require_paths:
|
|
111
112
|
- lib
|
112
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
114
|
requirements:
|
114
|
-
- -
|
115
|
+
- - ">="
|
115
116
|
- !ruby/object:Gem::Version
|
116
117
|
version: '0'
|
117
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
|
-
- -
|
120
|
+
- - ">="
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
requirements: []
|
123
124
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.4.8
|
125
126
|
signing_key:
|
126
127
|
specification_version: 4
|
127
128
|
summary: Rack jwt auth middleware
|