jwt 2.2.2 → 2.2.3
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/.github/workflows/test.yml +74 -0
- data/.rspec +1 -0
- data/.rubocop.yml +15 -16
- data/.rubocop_todo.yml +191 -0
- data/{.ebert.yml → .sourcelevel.yml} +1 -1
- data/AUTHORS +60 -43
- data/Appraisals +4 -12
- data/CHANGELOG.md +60 -5
- data/Gemfile +2 -0
- data/README.md +44 -5
- data/Rakefile +4 -1
- data/lib/jwt/algos.rb +44 -0
- data/lib/jwt/algos/none.rb +15 -0
- data/lib/jwt/algos/unsupported.rb +5 -4
- data/lib/jwt/claims_validator.rb +9 -7
- data/lib/jwt/decode.rb +9 -7
- data/lib/jwt/encode.rb +5 -4
- data/lib/jwt/jwk.rb +29 -9
- data/lib/jwt/jwk/ec.rb +150 -0
- data/lib/jwt/jwk/hmac.rb +58 -0
- data/lib/jwt/jwk/key_base.rb +18 -0
- data/lib/jwt/jwk/key_finder.rb +6 -1
- data/lib/jwt/jwk/rsa.rb +84 -23
- data/lib/jwt/signature.rb +7 -22
- data/lib/jwt/version.rb +1 -1
- data/ruby-jwt.gemspec +1 -7
- metadata +11 -76
- data/.codeclimate.yml +0 -20
- data/.travis.yml +0 -29
data/Appraisals
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
appraise 'standalone' do
|
|
2
2
|
end
|
|
3
3
|
|
|
4
|
-
appraise '
|
|
5
|
-
gem '
|
|
4
|
+
appraise 'openssl' do
|
|
5
|
+
gem 'openssl', '~> 2.1'
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
appraise '
|
|
9
|
-
gem '
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
appraise 'rails-5.2' do
|
|
13
|
-
gem 'rails', '~> 5.2.0'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
appraise 'rails-6.0' do
|
|
17
|
-
gem 'rails', '~> 6.0.0'
|
|
8
|
+
appraise 'rbnacl' do
|
|
9
|
+
gem 'rbnacl'
|
|
18
10
|
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.3](https://github.com/jwt/ruby-jwt/tree/2.2.3) (2021-04-19)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/jwt/ruby-jwt/compare/v2.2.2...2.2.3)
|
|
6
|
+
|
|
7
|
+
**Implemented enhancements:**
|
|
8
|
+
|
|
9
|
+
- Verify algorithm before evaluating keyfinder [\#343](https://github.com/jwt/ruby-jwt/issues/343)
|
|
10
|
+
- Why jwt depends on json \< 2.0 ? [\#179](https://github.com/jwt/ruby-jwt/issues/179)
|
|
11
|
+
- Support for JWK in-lieu of rsa\_public [\#158](https://github.com/jwt/ruby-jwt/issues/158)
|
|
12
|
+
- Fix rspec `raise_error` warning [\#413](https://github.com/jwt/ruby-jwt/pull/413) ([excpt](https://github.com/excpt))
|
|
13
|
+
- Add support for JWKs with HMAC key type. [\#372](https://github.com/jwt/ruby-jwt/pull/372) ([phlegx](https://github.com/phlegx))
|
|
14
|
+
- Improve 'none' algorithm handling [\#365](https://github.com/jwt/ruby-jwt/pull/365) ([danleyden](https://github.com/danleyden))
|
|
15
|
+
- Handle parsed JSON JWKS input with string keys [\#348](https://github.com/jwt/ruby-jwt/pull/348) ([martinemde](https://github.com/martinemde))
|
|
16
|
+
- Allow Numeric values during encoding [\#327](https://github.com/jwt/ruby-jwt/pull/327) ([fanfilmu](https://github.com/fanfilmu))
|
|
17
|
+
|
|
18
|
+
**Closed issues:**
|
|
19
|
+
|
|
20
|
+
- "Signature verification raised", yet jwt.io says "Signature Verified" [\#401](https://github.com/jwt/ruby-jwt/issues/401)
|
|
21
|
+
- truffleruby-head build is failing [\#396](https://github.com/jwt/ruby-jwt/issues/396)
|
|
22
|
+
- JWT::JWK::EC needs `require 'forwardable'` [\#392](https://github.com/jwt/ruby-jwt/issues/392)
|
|
23
|
+
- How to use a 'signing key' as used by next-auth [\#389](https://github.com/jwt/ruby-jwt/issues/389)
|
|
24
|
+
- undefined method `verify' for nil:NilClass when validate a JWT with JWK [\#383](https://github.com/jwt/ruby-jwt/issues/383)
|
|
25
|
+
- Make specifying "algorithm" optional on decode [\#380](https://github.com/jwt/ruby-jwt/issues/380)
|
|
26
|
+
- ADFS created access tokens can't be validated due to missing 'kid' header [\#370](https://github.com/jwt/ruby-jwt/issues/370)
|
|
27
|
+
- new version? [\#355](https://github.com/jwt/ruby-jwt/issues/355)
|
|
28
|
+
- JWT gitlab OmniAuth provider setup support [\#354](https://github.com/jwt/ruby-jwt/issues/354)
|
|
29
|
+
- Release with support for RSA.import for ruby \< 2.4 hasn't been released [\#347](https://github.com/jwt/ruby-jwt/issues/347)
|
|
30
|
+
- cannot load such file -- jwt [\#339](https://github.com/jwt/ruby-jwt/issues/339)
|
|
31
|
+
|
|
32
|
+
**Merged pull requests:**
|
|
33
|
+
|
|
34
|
+
- Remove codeclimate code coverage dev dependency [\#414](https://github.com/jwt/ruby-jwt/pull/414) ([excpt](https://github.com/excpt))
|
|
35
|
+
- Add forwardable dependency [\#408](https://github.com/jwt/ruby-jwt/pull/408) ([anakinj](https://github.com/anakinj))
|
|
36
|
+
- Ignore casing of algorithm [\#405](https://github.com/jwt/ruby-jwt/pull/405) ([johnnyshields](https://github.com/johnnyshields))
|
|
37
|
+
- Document function and add tests for verify claims method [\#404](https://github.com/jwt/ruby-jwt/pull/404) ([yasonk](https://github.com/yasonk))
|
|
38
|
+
- documenting calling verify\_jti callback with 2 arguments in the readme [\#402](https://github.com/jwt/ruby-jwt/pull/402) ([HoneyryderChuck](https://github.com/HoneyryderChuck))
|
|
39
|
+
- Target the master branch on the build status badge [\#399](https://github.com/jwt/ruby-jwt/pull/399) ([anakinj](https://github.com/anakinj))
|
|
40
|
+
- Improving the local development experience [\#397](https://github.com/jwt/ruby-jwt/pull/397) ([anakinj](https://github.com/anakinj))
|
|
41
|
+
- Fix sourcelevel broken links [\#395](https://github.com/jwt/ruby-jwt/pull/395) ([anakinj](https://github.com/anakinj))
|
|
42
|
+
- Don't recommend installing gem with sudo [\#391](https://github.com/jwt/ruby-jwt/pull/391) ([tjschuck](https://github.com/tjschuck))
|
|
43
|
+
- Enable rubocop locally and on ci [\#390](https://github.com/jwt/ruby-jwt/pull/390) ([anakinj](https://github.com/anakinj))
|
|
44
|
+
- Ci and test cleanup [\#387](https://github.com/jwt/ruby-jwt/pull/387) ([anakinj](https://github.com/anakinj))
|
|
45
|
+
- Make JWT::JWK::EC compatible with Ruby 2.3 [\#386](https://github.com/jwt/ruby-jwt/pull/386) ([anakinj](https://github.com/anakinj))
|
|
46
|
+
- Support JWKs for pre 2.3 rubies [\#382](https://github.com/jwt/ruby-jwt/pull/382) ([anakinj](https://github.com/anakinj))
|
|
47
|
+
- Replace Travis CI with GitHub Actions \(also favor openssl/rbnacl combinations over rails compatibility tests\) [\#381](https://github.com/jwt/ruby-jwt/pull/381) ([anakinj](https://github.com/anakinj))
|
|
48
|
+
- Add auth0 sponsor message [\#379](https://github.com/jwt/ruby-jwt/pull/379) ([excpt](https://github.com/excpt))
|
|
49
|
+
- Adapt HMAC to JWK RSA code style. [\#378](https://github.com/jwt/ruby-jwt/pull/378) ([phlegx](https://github.com/phlegx))
|
|
50
|
+
- Disable Rails cops [\#376](https://github.com/jwt/ruby-jwt/pull/376) ([anakinj](https://github.com/anakinj))
|
|
51
|
+
- Support exporting RSA JWK private keys [\#375](https://github.com/jwt/ruby-jwt/pull/375) ([anakinj](https://github.com/anakinj))
|
|
52
|
+
- Ebert is SourceLevel nowadays [\#374](https://github.com/jwt/ruby-jwt/pull/374) ([anakinj](https://github.com/anakinj))
|
|
53
|
+
- Add support for JWKs with EC key type [\#371](https://github.com/jwt/ruby-jwt/pull/371) ([richardlarocque](https://github.com/richardlarocque))
|
|
54
|
+
- Add Truffleruby head to CI [\#368](https://github.com/jwt/ruby-jwt/pull/368) ([gogainda](https://github.com/gogainda))
|
|
55
|
+
- Add more docs about JWK support [\#341](https://github.com/jwt/ruby-jwt/pull/341) ([take](https://github.com/take))
|
|
56
|
+
|
|
3
57
|
## [v2.2.2](https://github.com/jwt/ruby-jwt/tree/v2.2.2) (2020-08-18)
|
|
4
58
|
|
|
5
59
|
[Full Changelog](https://github.com/jwt/ruby-jwt/compare/v2.2.1...v2.2.2)
|
|
@@ -33,7 +87,7 @@
|
|
|
33
87
|
- Sinatra 4.90s TTFB [\#344](https://github.com/jwt/ruby-jwt/issues/344)
|
|
34
88
|
- How to Logout [\#342](https://github.com/jwt/ruby-jwt/issues/342)
|
|
35
89
|
- jwt token decoding even when wrong token is provided for some letters [\#337](https://github.com/jwt/ruby-jwt/issues/337)
|
|
36
|
-
- Need to use `
|
|
90
|
+
- Need to use `symbolize_keys` everywhere! [\#330](https://github.com/jwt/ruby-jwt/issues/330)
|
|
37
91
|
- eval\(\) used in Forwardable limits usage in iOS App Store [\#324](https://github.com/jwt/ruby-jwt/issues/324)
|
|
38
92
|
- HS512256 OpenSSL Exception: First num too large [\#322](https://github.com/jwt/ruby-jwt/issues/322)
|
|
39
93
|
- Can we change the separator character? [\#321](https://github.com/jwt/ruby-jwt/issues/321)
|
|
@@ -43,6 +97,7 @@
|
|
|
43
97
|
|
|
44
98
|
**Merged pull requests:**
|
|
45
99
|
|
|
100
|
+
- Release v2.2.2 [\#367](https://github.com/jwt/ruby-jwt/pull/367) ([excpt](https://github.com/excpt))
|
|
46
101
|
- Fix 'already initialized constant JWT Error' [\#357](https://github.com/jwt/ruby-jwt/pull/357) ([excpt](https://github.com/excpt))
|
|
47
102
|
- Support RSA.import for all Ruby versions. [\#333](https://github.com/jwt/ruby-jwt/pull/333) ([rabajaj0509](https://github.com/rabajaj0509))
|
|
48
103
|
- Removed forwardable dependency [\#325](https://github.com/jwt/ruby-jwt/pull/325) ([anakinj](https://github.com/anakinj))
|
|
@@ -140,7 +195,7 @@
|
|
|
140
195
|
- improving code quality of jwt module [\#266](https://github.com/jwt/ruby-jwt/pull/266) ([ab320012](https://github.com/ab320012))
|
|
141
196
|
- fixed ECDSA supported versions const [\#263](https://github.com/jwt/ruby-jwt/pull/263) ([starbeast](https://github.com/starbeast))
|
|
142
197
|
- Added my name to contributor list [\#262](https://github.com/jwt/ruby-jwt/pull/262) ([ab320012](https://github.com/ab320012))
|
|
143
|
-
- Use `Class
|
|
198
|
+
- Use `Class#new` Shorthand For Error Subclasses [\#255](https://github.com/jwt/ruby-jwt/pull/255) ([akabiru](https://github.com/akabiru))
|
|
144
199
|
- \[CI\] Test against Ruby 2.5 [\#253](https://github.com/jwt/ruby-jwt/pull/253) ([nicolasleger](https://github.com/nicolasleger))
|
|
145
200
|
- Fix README [\#250](https://github.com/jwt/ruby-jwt/pull/250) ([rono23](https://github.com/rono23))
|
|
146
201
|
- Fix link format [\#248](https://github.com/jwt/ruby-jwt/pull/248) ([y-yagi](https://github.com/y-yagi))
|
|
@@ -162,6 +217,7 @@
|
|
|
162
217
|
**Fixed bugs:**
|
|
163
218
|
|
|
164
219
|
- JWT.encode failing on encode for string [\#235](https://github.com/jwt/ruby-jwt/issues/235)
|
|
220
|
+
- The README says it uses an algorithm by default [\#226](https://github.com/jwt/ruby-jwt/issues/226)
|
|
165
221
|
- Fix string payload issue [\#236](https://github.com/jwt/ruby-jwt/pull/236) ([excpt](https://github.com/excpt))
|
|
166
222
|
|
|
167
223
|
**Security fixes:**
|
|
@@ -186,7 +242,6 @@
|
|
|
186
242
|
|
|
187
243
|
**Fixed bugs:**
|
|
188
244
|
|
|
189
|
-
- The README says it uses an algorithm by default [\#226](https://github.com/jwt/ruby-jwt/issues/226)
|
|
190
245
|
- Support versions outside 2.1 [\#209](https://github.com/jwt/ruby-jwt/issues/209)
|
|
191
246
|
- Verifying expiration without leeway throws exception [\#206](https://github.com/jwt/ruby-jwt/issues/206)
|
|
192
247
|
- Ruby interpreter warning [\#200](https://github.com/jwt/ruby-jwt/issues/200)
|
|
@@ -237,7 +292,6 @@
|
|
|
237
292
|
- The leeway parameter is applies to all time based verifications [\#129](https://github.com/jwt/ruby-jwt/issues/129)
|
|
238
293
|
- Make algorithm option required to verify signature [\#184](https://github.com/jwt/ruby-jwt/pull/184) ([EmilioCristalli](https://github.com/EmilioCristalli))
|
|
239
294
|
- Validate audience when payload is a scalar and options is an array [\#183](https://github.com/jwt/ruby-jwt/pull/183) ([steti](https://github.com/steti))
|
|
240
|
-
- Fix: exp claim check [\#161](https://github.com/jwt/ruby-jwt/pull/161) ([excpt](https://github.com/excpt))
|
|
241
295
|
|
|
242
296
|
**Closed issues:**
|
|
243
297
|
|
|
@@ -291,6 +345,7 @@
|
|
|
291
345
|
- Audience Claim broken? [\#151](https://github.com/jwt/ruby-jwt/issues/151)
|
|
292
346
|
- 1.5.3 breaks compatibility with 1.5.2 [\#133](https://github.com/jwt/ruby-jwt/issues/133)
|
|
293
347
|
- Version 1.5.3 breaks 1.9.3 compatibility, but not documented as such [\#132](https://github.com/jwt/ruby-jwt/issues/132)
|
|
348
|
+
- Fix: exp claim check [\#161](https://github.com/jwt/ruby-jwt/pull/161) ([excpt](https://github.com/excpt))
|
|
294
349
|
|
|
295
350
|
**Security fixes:**
|
|
296
351
|
|
|
@@ -461,7 +516,6 @@
|
|
|
461
516
|
|
|
462
517
|
- Fix \#66 \#68 [\#69](https://github.com/jwt/ruby-jwt/pull/69) ([excpt](https://github.com/excpt))
|
|
463
518
|
- When throwing errors, mention expected/received values [\#65](https://github.com/jwt/ruby-jwt/pull/65) ([rolodato](https://github.com/rolodato))
|
|
464
|
-
- Add 'iss' support for ruby-jwt [\#61](https://github.com/jwt/ruby-jwt/pull/61) ([ZhangHanDong](https://github.com/ZhangHanDong))
|
|
465
519
|
|
|
466
520
|
## [jwt-1.4.0](https://github.com/jwt/ruby-jwt/tree/jwt-1.4.0) (2015-03-10)
|
|
467
521
|
|
|
@@ -476,6 +530,7 @@
|
|
|
476
530
|
- Release 1.4.0 [\#64](https://github.com/jwt/ruby-jwt/pull/64) ([excpt](https://github.com/excpt))
|
|
477
531
|
- Update README.md and remove dead code [\#63](https://github.com/jwt/ruby-jwt/pull/63) ([excpt](https://github.com/excpt))
|
|
478
532
|
- Add 'iat/ aud/ sub/ jti' support for ruby-jwt [\#62](https://github.com/jwt/ruby-jwt/pull/62) ([ZhangHanDong](https://github.com/ZhangHanDong))
|
|
533
|
+
- Add 'iss' support for ruby-jwt [\#61](https://github.com/jwt/ruby-jwt/pull/61) ([ZhangHanDong](https://github.com/ZhangHanDong))
|
|
479
534
|
- Clarify .encode API in README [\#60](https://github.com/jwt/ruby-jwt/pull/60) ([jbodah](https://github.com/jbodah))
|
|
480
535
|
|
|
481
536
|
## [jwt-1.3.0](https://github.com/jwt/ruby-jwt/tree/jwt-1.3.0) (2015-02-24)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# JWT
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/jwt)
|
|
4
|
-
[](https://github.com/jwt/ruby-jwt/actions)
|
|
5
5
|
[](https://codeclimate.com/github/jwt/ruby-jwt)
|
|
6
6
|
[](https://codeclimate.com/github/jwt/ruby-jwt/coverage)
|
|
7
7
|
[](https://codeclimate.com/github/jwt/ruby-jwt)
|
|
8
|
-
[](https://app.sourcelevel.io/github/jwt/-/ruby-jwt)
|
|
9
9
|
|
|
10
10
|
A ruby implementation of the [RFC 7519 OAuth JSON Web Token (JWT)](https://tools.ietf.org/html/rfc7519) standard.
|
|
11
11
|
|
|
@@ -16,11 +16,17 @@ If you have further questions related to development or usage, join us: [ruby-jw
|
|
|
16
16
|
* Ruby 1.9.3 support was dropped at December 31st, 2016.
|
|
17
17
|
* Version 1.5.3 yanked. See: [#132](https://github.com/jwt/ruby-jwt/issues/132) and [#133](https://github.com/jwt/ruby-jwt/issues/133)
|
|
18
18
|
|
|
19
|
+
## Sponsors
|
|
20
|
+
|
|
21
|
+
|Logo|Message|
|
|
22
|
+
|-|-|
|
|
23
|
+
||If you want to quickly add secure token-based authentication to Ruby projects, feel free to check Auth0's Ruby SDK and free plan at [auth0.com/developers](https://auth0.com/developers?utm_source=GHsponsor&utm_medium=GHsponsor&utm_campaign=rubyjwt&utm_content=auth)|
|
|
24
|
+
|
|
19
25
|
## Installing
|
|
20
26
|
|
|
21
27
|
### Using Rubygems:
|
|
22
28
|
```bash
|
|
23
|
-
|
|
29
|
+
gem install jwt
|
|
24
30
|
```
|
|
25
31
|
|
|
26
32
|
### Using Bundler:
|
|
@@ -285,6 +291,12 @@ rescue JWT::ExpiredSignature
|
|
|
285
291
|
end
|
|
286
292
|
```
|
|
287
293
|
|
|
294
|
+
The Expiration Claim verification can be disabled.
|
|
295
|
+
```ruby
|
|
296
|
+
# Decode token without raising JWT::ExpiredSignature error
|
|
297
|
+
JWT.decode token, hmac_secret, true, { verify_expiration: false, algorithm: 'HS256' }
|
|
298
|
+
```
|
|
299
|
+
|
|
288
300
|
**Adding Leeway**
|
|
289
301
|
|
|
290
302
|
```ruby
|
|
@@ -325,6 +337,12 @@ rescue JWT::ImmatureSignature
|
|
|
325
337
|
end
|
|
326
338
|
```
|
|
327
339
|
|
|
340
|
+
The Not Before Claim verification can be disabled.
|
|
341
|
+
```ruby
|
|
342
|
+
# Decode token without raising JWT::ImmatureSignature error
|
|
343
|
+
JWT.decode token, hmac_secret, true, { verify_not_before: false, algorithm: 'HS256' }
|
|
344
|
+
```
|
|
345
|
+
|
|
328
346
|
**Adding Leeway**
|
|
329
347
|
|
|
330
348
|
```ruby
|
|
@@ -406,6 +424,8 @@ begin
|
|
|
406
424
|
#decoded_token = JWT.decode token, hmac_secret, true, { verify_jti: true, algorithm: 'HS256' }
|
|
407
425
|
# Alternatively, pass a proc with your own code to check if the JTI has already been used
|
|
408
426
|
decoded_token = JWT.decode token, hmac_secret, true, { verify_jti: proc { |jti| my_validation_method(jti) }, algorithm: 'HS256' }
|
|
427
|
+
# or
|
|
428
|
+
decoded_token = JWT.decode token, hmac_secret, true, { verify_jti: proc { |jti, payload| my_validation_method(jti, payload) }, algorithm: 'HS256' }
|
|
409
429
|
rescue JWT::InvalidJtiError
|
|
410
430
|
# Handle invalid token, e.g. logout user or deny access
|
|
411
431
|
puts 'Error'
|
|
@@ -479,6 +499,24 @@ rescue JWT::DecodeError
|
|
|
479
499
|
end
|
|
480
500
|
```
|
|
481
501
|
|
|
502
|
+
or by passing JWK as a simple Hash
|
|
503
|
+
|
|
504
|
+
```
|
|
505
|
+
jwks = { keys: [{ ... }] } # keys needs to be Symbol
|
|
506
|
+
JWT.decode(token, nil, true, { algorithms: ['RS512'], jwks: jwks})
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### Importing and exporting JSON Web Keys
|
|
510
|
+
|
|
511
|
+
The ::JWT::JWK class can be used to import and export both the public key (default behaviour) and the private key. To include the private key in the export pass the `include_private` parameter to the export method.
|
|
512
|
+
|
|
513
|
+
```ruby
|
|
514
|
+
jwk = JWT::JWK.new(OpenSSL::PKey::RSA.new(2048))
|
|
515
|
+
|
|
516
|
+
jwk_hash = jwk.export
|
|
517
|
+
jwk_hash_with_private_key = jwk.export(include_private: true)
|
|
518
|
+
```
|
|
519
|
+
|
|
482
520
|
# Development and Tests
|
|
483
521
|
|
|
484
522
|
We depend on [Bundler](http://rubygems.org/gems/bundler) for defining gemspec and performing releases to rubygems.org, which can be done with
|
|
@@ -487,10 +525,11 @@ We depend on [Bundler](http://rubygems.org/gems/bundler) for defining gemspec an
|
|
|
487
525
|
rake release
|
|
488
526
|
```
|
|
489
527
|
|
|
490
|
-
The tests are written with rspec.
|
|
528
|
+
The tests are written with rspec. [Appraisal](https://github.com/thoughtbot/appraisal) is used to ensure compatibility with 3rd party dependencies providing cryptographic features.
|
|
491
529
|
|
|
492
530
|
```bash
|
|
493
|
-
bundle
|
|
531
|
+
bundle install
|
|
532
|
+
bundle exec appraisal rake test
|
|
494
533
|
```
|
|
495
534
|
|
|
496
535
|
**If you want a release cut with your PR, please include a version bump according to [Semantic Versioning](http://semver.org/)**
|
data/Rakefile
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
1
2
|
require 'bundler/gem_tasks'
|
|
2
3
|
|
|
3
4
|
begin
|
|
4
5
|
require 'rspec/core/rake_task'
|
|
6
|
+
require 'rubocop/rake_task'
|
|
5
7
|
|
|
6
8
|
RSpec::Core::RakeTask.new(:test)
|
|
9
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
7
10
|
|
|
8
|
-
task default:
|
|
11
|
+
task default: %i[rubocop test]
|
|
9
12
|
rescue LoadError
|
|
10
13
|
puts 'RSpec rake tasks not available. Please run "bundle install" to install missing dependencies.'
|
|
11
14
|
end
|
data/lib/jwt/algos.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'jwt/algos/hmac'
|
|
4
|
+
require 'jwt/algos/eddsa'
|
|
5
|
+
require 'jwt/algos/ecdsa'
|
|
6
|
+
require 'jwt/algos/rsa'
|
|
7
|
+
require 'jwt/algos/ps'
|
|
8
|
+
require 'jwt/algos/none'
|
|
9
|
+
require 'jwt/algos/unsupported'
|
|
10
|
+
|
|
11
|
+
# JWT::Signature module
|
|
12
|
+
module JWT
|
|
13
|
+
# Signature logic for JWT
|
|
14
|
+
module Algos
|
|
15
|
+
extend self
|
|
16
|
+
|
|
17
|
+
ALGOS = [
|
|
18
|
+
Algos::Hmac,
|
|
19
|
+
Algos::Ecdsa,
|
|
20
|
+
Algos::Rsa,
|
|
21
|
+
Algos::Eddsa,
|
|
22
|
+
Algos::Ps,
|
|
23
|
+
Algos::None,
|
|
24
|
+
Algos::Unsupported
|
|
25
|
+
].freeze
|
|
26
|
+
|
|
27
|
+
def find(algorithm)
|
|
28
|
+
indexed[algorithm && algorithm.downcase]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def indexed
|
|
34
|
+
@indexed ||= begin
|
|
35
|
+
fallback = [Algos::Unsupported, nil]
|
|
36
|
+
ALGOS.each_with_object(Hash.new(fallback)) do |alg, hash|
|
|
37
|
+
alg.const_get(:SUPPORTED).each do |code|
|
|
38
|
+
hash[code.downcase] = [alg, code]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -3,14 +3,15 @@ module JWT
|
|
|
3
3
|
module Unsupported
|
|
4
4
|
module_function
|
|
5
5
|
|
|
6
|
-
SUPPORTED =
|
|
7
|
-
def verify(*)
|
|
8
|
-
raise JWT::VerificationError, 'Algorithm not supported'
|
|
9
|
-
end
|
|
6
|
+
SUPPORTED = [].freeze
|
|
10
7
|
|
|
11
8
|
def sign(*)
|
|
12
9
|
raise NotImplementedError, 'Unsupported signing method'
|
|
13
10
|
end
|
|
11
|
+
|
|
12
|
+
def verify(*)
|
|
13
|
+
raise JWT::VerificationError, 'Algorithm not supported'
|
|
14
|
+
end
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|
data/lib/jwt/claims_validator.rb
CHANGED
|
@@ -2,7 +2,7 @@ require_relative './error'
|
|
|
2
2
|
|
|
3
3
|
module JWT
|
|
4
4
|
class ClaimsValidator
|
|
5
|
-
|
|
5
|
+
NUMERIC_CLAIMS = %i[
|
|
6
6
|
exp
|
|
7
7
|
iat
|
|
8
8
|
nbf
|
|
@@ -13,21 +13,23 @@ module JWT
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def validate!
|
|
16
|
-
|
|
16
|
+
validate_numeric_claims
|
|
17
17
|
|
|
18
18
|
true
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
22
22
|
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
def validate_numeric_claims
|
|
24
|
+
NUMERIC_CLAIMS.each do |claim|
|
|
25
|
+
validate_is_numeric(claim) if @payload.key?(claim)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def
|
|
30
|
-
|
|
29
|
+
def validate_is_numeric(claim)
|
|
30
|
+
return if @payload[claim].is_a?(Numeric)
|
|
31
|
+
|
|
32
|
+
raise InvalidPayload, "#{claim} claim must be a Numeric value but it is a #{@payload[claim].class}"
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
end
|
data/lib/jwt/decode.rb
CHANGED
|
@@ -43,22 +43,23 @@ module JWT
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def options_includes_algo_in_header?
|
|
46
|
-
allowed_algorithms.
|
|
46
|
+
allowed_algorithms.any? { |alg| alg.casecmp(header['alg']).zero? }
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def allowed_algorithms
|
|
50
50
|
# Order is very important - first check for string keys, next for symbols
|
|
51
|
-
if @options.key?('algorithm')
|
|
52
|
-
|
|
51
|
+
algos = if @options.key?('algorithm')
|
|
52
|
+
@options['algorithm']
|
|
53
53
|
elsif @options.key?(:algorithm)
|
|
54
|
-
|
|
54
|
+
@options[:algorithm]
|
|
55
55
|
elsif @options.key?('algorithms')
|
|
56
|
-
@options['algorithms']
|
|
56
|
+
@options['algorithms']
|
|
57
57
|
elsif @options.key?(:algorithms)
|
|
58
|
-
@options[:algorithms]
|
|
58
|
+
@options[:algorithms]
|
|
59
59
|
else
|
|
60
60
|
[]
|
|
61
61
|
end
|
|
62
|
+
Array(algos)
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
def find_key(&keyfinder)
|
|
@@ -74,6 +75,7 @@ module JWT
|
|
|
74
75
|
def validate_segment_count!
|
|
75
76
|
return if segment_length == 3
|
|
76
77
|
return if !@verify && segment_length == 2 # If no verifying required, the signature is not needed
|
|
78
|
+
return if segment_length == 2 && header['alg'] == 'none'
|
|
77
79
|
|
|
78
80
|
raise(JWT::DecodeError, 'Not enough or too many segments')
|
|
79
81
|
end
|
|
@@ -83,7 +85,7 @@ module JWT
|
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
def decode_crypto
|
|
86
|
-
@signature = JWT::Base64.url_decode(@segments[2])
|
|
88
|
+
@signature = JWT::Base64.url_decode(@segments[2] || '')
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
def header
|