jwt-auth 4.2.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -0
  3. data/Gemfile +3 -0
  4. data/README.md +119 -18
  5. data/bin/build +22 -0
  6. data/bin/release +40 -0
  7. data/jwt-auth.gemspec +18 -15
  8. data/lib/jwt/auth.rb +2 -0
  9. data/lib/jwt/auth/access_token.rb +20 -0
  10. data/lib/jwt/auth/authenticatable.rb +16 -0
  11. data/lib/jwt/auth/authentication.rb +63 -22
  12. data/lib/jwt/auth/configuration.rb +4 -1
  13. data/lib/jwt/auth/refresh_token.rb +20 -0
  14. data/lib/jwt/auth/token.rb +49 -41
  15. data/lib/jwt/auth/version.rb +3 -1
  16. data/spec/controllers/content_controller_spec.rb +95 -0
  17. data/spec/controllers/tokens_controller_spec.rb +140 -0
  18. data/spec/dummy/Rakefile +2 -0
  19. data/spec/dummy/app/channels/application_cable/channel.rb +2 -0
  20. data/spec/dummy/app/channels/application_cable/connection.rb +2 -0
  21. data/spec/dummy/app/controllers/application_controller.rb +6 -1
  22. data/spec/dummy/app/controllers/content_controller.rb +29 -0
  23. data/spec/dummy/app/controllers/tokens_controller.rb +53 -0
  24. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  25. data/spec/dummy/app/helpers/authentication_helper.rb +2 -0
  26. data/spec/dummy/app/jobs/application_job.rb +2 -0
  27. data/spec/dummy/app/mailers/application_mailer.rb +3 -1
  28. data/spec/dummy/app/models/application_record.rb +2 -0
  29. data/spec/dummy/app/models/user.rb +3 -6
  30. data/spec/dummy/bin/bundle +2 -0
  31. data/spec/dummy/bin/rails +2 -0
  32. data/spec/dummy/bin/rake +2 -0
  33. data/spec/dummy/bin/setup +2 -0
  34. data/spec/dummy/bin/update +2 -0
  35. data/spec/dummy/bin/yarn +7 -7
  36. data/spec/dummy/config.ru +2 -0
  37. data/spec/dummy/config/application.rb +2 -0
  38. data/spec/dummy/config/boot.rb +3 -1
  39. data/spec/dummy/config/environment.rb +2 -0
  40. data/spec/dummy/config/environments/development.rb +3 -1
  41. data/spec/dummy/config/environments/production.rb +4 -2
  42. data/spec/dummy/config/environments/test.rb +2 -0
  43. data/spec/dummy/config/initializers/application_controller_renderer.rb +2 -0
  44. data/spec/dummy/config/initializers/assets.rb +2 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +2 -0
  46. data/spec/dummy/config/initializers/content_security_policy.rb +2 -0
  47. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  48. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  49. data/spec/dummy/config/initializers/inflections.rb +2 -0
  50. data/spec/dummy/config/initializers/jwt_auth.rb +9 -2
  51. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  52. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +2 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +3 -1
  54. data/spec/dummy/config/puma.rb +5 -3
  55. data/spec/dummy/config/routes.rb +5 -4
  56. data/spec/dummy/config/spring.rb +4 -2
  57. data/spec/dummy/db/migrate/20170726110751_create_users.rb +2 -0
  58. data/spec/dummy/db/migrate/20170726110825_add_token_version_to_user.rb +2 -0
  59. data/spec/dummy/db/migrate/20170726112117_add_activated_to_user.rb +2 -0
  60. data/spec/dummy/db/migrate/20190221100103_add_password_to_user.rb +7 -0
  61. data/spec/dummy/db/schema.rb +10 -9
  62. data/spec/jwt/auth/access_token_spec.rb +35 -0
  63. data/spec/jwt/auth/configuration_spec.rb +36 -0
  64. data/spec/jwt/auth/refresh_token_spec.rb +35 -0
  65. data/spec/jwt/auth/token_spec.rb +144 -0
  66. data/spec/models/user_spec.rb +24 -0
  67. data/spec/rails_helper.rb +8 -0
  68. data/spec/spec_helper.rb +51 -53
  69. data/spec/support/database_cleaner.rb +22 -0
  70. data/spec/support/matchers/return_token.rb +33 -0
  71. data/version.yml +1 -0
  72. metadata +119 -54
  73. data/spec/authentication_spec.rb +0 -136
  74. data/spec/configuration_spec.rb +0 -18
  75. data/spec/dummy/app/controllers/authentication_controller.rb +0 -22
  76. data/spec/token_spec.rb +0 -125
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/expectations'
4
+
5
+ RSpec::Matchers.define :return_token do |type|
6
+ match do
7
+ @actual = nil
8
+
9
+ return false unless response.headers['Authorization']
10
+
11
+ jwt = response.headers['Authorization'].scan(/Bearer (.*)$/).flatten.last
12
+
13
+ return false unless jwt
14
+
15
+ token = JWT::Auth::Token.from_jwt jwt
16
+
17
+ return false unless jwt
18
+
19
+ @actual = token.class
20
+
21
+ if type.nil?
22
+ # If the `type` argument was specified, check for existence
23
+ !token.nil?
24
+ else
25
+ # Otherwise check for token type
26
+ token.is_a? type
27
+ end
28
+ end
29
+
30
+ diffable
31
+
32
+ description { 'return a token in the response headers' }
33
+ end
@@ -0,0 +1 @@
1
+ --- 5.0.0
metadata CHANGED
@@ -1,143 +1,143 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-06 00:00:00.000000000 Z
11
+ date: 2019-03-06 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: '2.0'
19
+ version: '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: '2.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '5.2'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.17'
47
+ version: '0'
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
- version: '1.17'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.63'
61
+ version: '0'
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
- version: '0.63'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: coveralls
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '12.3'
75
+ version: '0'
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
- version: '12.3'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: database_cleaner
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '3.8'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '3.8'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rspec-rails
98
+ name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '3.8'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '3.8'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rdoc
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '6.1'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '6.1'
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: coveralls
126
+ name: rspec
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0.8'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '0.8'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: byebug
140
+ name: rspec-rails
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,35 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: sqlite3
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: semverse
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: shoulda-matchers
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - ">="
@@ -164,10 +192,26 @@ dependencies:
164
192
  - - ">="
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sqlite3
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.3.6
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.3.6
167
209
  description: Authentication middleware for Rails API that uses JWTs
168
210
  email:
169
211
  - florian@floriandejonckheere.be
170
- executables: []
212
+ executables:
213
+ - build
214
+ - release
171
215
  extensions: []
172
216
  extra_rdoc_files: []
173
217
  files:
@@ -179,16 +223,20 @@ files:
179
223
  - LICENSE.md
180
224
  - README.md
181
225
  - Rakefile
226
+ - bin/build
227
+ - bin/release
182
228
  - jwt-auth.gemspec
183
229
  - lib/jwt/auth.rb
230
+ - lib/jwt/auth/access_token.rb
184
231
  - lib/jwt/auth/authenticatable.rb
185
232
  - lib/jwt/auth/authentication.rb
186
233
  - lib/jwt/auth/configuration.rb
187
234
  - lib/jwt/auth/errors.rb
235
+ - lib/jwt/auth/refresh_token.rb
188
236
  - lib/jwt/auth/token.rb
189
237
  - lib/jwt/auth/version.rb
190
- - spec/authentication_spec.rb
191
- - spec/configuration_spec.rb
238
+ - spec/controllers/content_controller_spec.rb
239
+ - spec/controllers/tokens_controller_spec.rb
192
240
  - spec/dummy/.gitignore
193
241
  - spec/dummy/Rakefile
194
242
  - spec/dummy/app/assets/config/manifest.js
@@ -200,8 +248,9 @@ files:
200
248
  - spec/dummy/app/channels/application_cable/channel.rb
201
249
  - spec/dummy/app/channels/application_cable/connection.rb
202
250
  - spec/dummy/app/controllers/application_controller.rb
203
- - spec/dummy/app/controllers/authentication_controller.rb
204
251
  - spec/dummy/app/controllers/concerns/.keep
252
+ - spec/dummy/app/controllers/content_controller.rb
253
+ - spec/dummy/app/controllers/tokens_controller.rb
205
254
  - spec/dummy/app/helpers/application_helper.rb
206
255
  - spec/dummy/app/helpers/authentication_helper.rb
207
256
  - spec/dummy/app/jobs/application_job.rb
@@ -247,6 +296,7 @@ files:
247
296
  - spec/dummy/db/migrate/20170726110751_create_users.rb
248
297
  - spec/dummy/db/migrate/20170726110825_add_token_version_to_user.rb
249
298
  - spec/dummy/db/migrate/20170726112117_add_activated_to_user.rb
299
+ - spec/dummy/db/migrate/20190221100103_add_password_to_user.rb
250
300
  - spec/dummy/db/schema.rb
251
301
  - spec/dummy/lib/assets/.keep
252
302
  - spec/dummy/log/.keep
@@ -258,10 +308,17 @@ files:
258
308
  - spec/dummy/public/apple-touch-icon.png
259
309
  - spec/dummy/public/favicon.ico
260
310
  - spec/dummy/tmp/.keep
311
+ - spec/jwt/auth/access_token_spec.rb
312
+ - spec/jwt/auth/configuration_spec.rb
313
+ - spec/jwt/auth/refresh_token_spec.rb
314
+ - spec/jwt/auth/token_spec.rb
315
+ - spec/models/user_spec.rb
261
316
  - spec/rails_helper.rb
262
317
  - spec/spec_helper.rb
263
318
  - spec/support/.keep
264
- - spec/token_spec.rb
319
+ - spec/support/database_cleaner.rb
320
+ - spec/support/matchers/return_token.rb
321
+ - version.yml
265
322
  homepage: https://github.com/floriandejonckheere/jwt-auth
266
323
  licenses:
267
324
  - MIT
@@ -286,8 +343,8 @@ signing_key:
286
343
  specification_version: 4
287
344
  summary: JWT-based authentication for Rails API
288
345
  test_files:
289
- - spec/authentication_spec.rb
290
- - spec/configuration_spec.rb
346
+ - spec/controllers/content_controller_spec.rb
347
+ - spec/controllers/tokens_controller_spec.rb
291
348
  - spec/dummy/.gitignore
292
349
  - spec/dummy/Rakefile
293
350
  - spec/dummy/app/assets/config/manifest.js
@@ -299,8 +356,9 @@ test_files:
299
356
  - spec/dummy/app/channels/application_cable/channel.rb
300
357
  - spec/dummy/app/channels/application_cable/connection.rb
301
358
  - spec/dummy/app/controllers/application_controller.rb
302
- - spec/dummy/app/controllers/authentication_controller.rb
303
359
  - spec/dummy/app/controllers/concerns/.keep
360
+ - spec/dummy/app/controllers/content_controller.rb
361
+ - spec/dummy/app/controllers/tokens_controller.rb
304
362
  - spec/dummy/app/helpers/application_helper.rb
305
363
  - spec/dummy/app/helpers/authentication_helper.rb
306
364
  - spec/dummy/app/jobs/application_job.rb
@@ -346,6 +404,7 @@ test_files:
346
404
  - spec/dummy/db/migrate/20170726110751_create_users.rb
347
405
  - spec/dummy/db/migrate/20170726110825_add_token_version_to_user.rb
348
406
  - spec/dummy/db/migrate/20170726112117_add_activated_to_user.rb
407
+ - spec/dummy/db/migrate/20190221100103_add_password_to_user.rb
349
408
  - spec/dummy/db/schema.rb
350
409
  - spec/dummy/lib/assets/.keep
351
410
  - spec/dummy/log/.keep
@@ -357,7 +416,13 @@ test_files:
357
416
  - spec/dummy/public/apple-touch-icon.png
358
417
  - spec/dummy/public/favicon.ico
359
418
  - spec/dummy/tmp/.keep
419
+ - spec/jwt/auth/access_token_spec.rb
420
+ - spec/jwt/auth/configuration_spec.rb
421
+ - spec/jwt/auth/refresh_token_spec.rb
422
+ - spec/jwt/auth/token_spec.rb
423
+ - spec/models/user_spec.rb
360
424
  - spec/rails_helper.rb
361
425
  - spec/spec_helper.rb
362
426
  - spec/support/.keep
363
- - spec/token_spec.rb
427
+ - spec/support/database_cleaner.rb
428
+ - spec/support/matchers/return_token.rb
@@ -1,136 +0,0 @@
1
- # frozen_string_listeral: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe AuthenticationController, :type => :request do
6
- let(:user) { User.create :activated => true }
7
-
8
- let(:headers) do
9
- {
10
- 'Authorization' => "Bearer #{JWT::Auth::Token.from_user(user).to_jwt}"
11
- }
12
- end
13
-
14
- describe 'GET /public' do
15
- context 'activated user' do
16
- it 'is accessible without token' do
17
- get '/public'
18
-
19
- expect(response.status).to eq 204
20
- end
21
-
22
- it 'is accessible with token' do
23
- get '/public', :headers => headers
24
-
25
- expect(response.status).to eq 204
26
- end
27
-
28
- it 'renews the token' do
29
- get '/public', :headers => headers
30
-
31
- jwt = response.headers['Authorization'].scan(/Bearer (.*)$/).flatten.last
32
- token = JWT::Auth::Token.from_token jwt
33
-
34
- expect(token).to be_valid
35
- end
36
- end
37
-
38
- context 'disabled user' do
39
- let(:user) { User.new }
40
-
41
- it 'is accessible without token' do
42
- get '/public'
43
-
44
- expect(response.status).to eq 204
45
- end
46
-
47
- it 'is accessible with token' do
48
- get '/public', :headers => headers
49
-
50
- expect(response.status).to eq 204
51
- end
52
- end
53
- end
54
-
55
- describe 'GET /private' do
56
- context 'activated user' do
57
- it 'is not accessible without token' do
58
- get '/private'
59
-
60
- expect(response.status).to eq 401
61
- end
62
-
63
- it 'is accessible with token' do
64
- get '/private', :headers => headers
65
-
66
- expect(response.status).to eq 204
67
- end
68
-
69
- it 'renews the token' do
70
- get '/private', :headers => headers
71
-
72
- jwt = response.headers['Authorization'].scan(/Bearer (.*)$/).flatten.last
73
- token = JWT::Auth::Token.from_token jwt
74
-
75
- expect(token).to be_valid
76
- end
77
- end
78
-
79
- context 'disabled user' do
80
- let(:user) { User.new }
81
-
82
- it 'is not accessible without token' do
83
- get '/private'
84
-
85
- expect(response.status).to eq 401
86
- end
87
-
88
- it 'is not accessible with token' do
89
- get '/private', :headers => headers
90
-
91
- expect(response.status).to eq 401
92
- end
93
- end
94
- end
95
-
96
- describe 'GET /validate' do
97
- context 'activated user' do
98
- it 'is accessible without token' do
99
- get '/validate'
100
-
101
- expect(response.status).to eq 204
102
- end
103
-
104
- it 'is accessible with token' do
105
- get '/validate', :headers => headers
106
-
107
- expect(response.status).to eq 204
108
- end
109
-
110
- it 'renews the token' do
111
- get '/validate', :headers => headers
112
-
113
- jwt = response.headers['Authorization'].scan(/Bearer (.*)$/).flatten.last
114
- token = JWT::Auth::Token.from_token jwt
115
-
116
- expect(token).to be_valid
117
- end
118
- end
119
-
120
- context 'disabled user' do
121
- let(:user) { User.new }
122
-
123
- it 'is accessible without token' do
124
- get '/validate'
125
-
126
- expect(response.status).to eq 204
127
- end
128
-
129
- it 'is not accessible with token' do
130
- get '/validate', :headers => headers
131
-
132
- expect(response.status).to eq 401
133
- end
134
- end
135
- end
136
- end