jwt 2.10.1 → 3.0.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/CHANGELOG.md +61 -32
- data/CODE_OF_CONDUCT.md +14 -14
- data/CONTRIBUTING.md +9 -10
- data/README.md +132 -151
- data/UPGRADING.md +47 -0
- data/lib/jwt/base64.rb +1 -10
- data/lib/jwt/claims/numeric.rb +0 -32
- data/lib/jwt/claims.rb +0 -7
- data/lib/jwt/configuration/container.rb +0 -1
- data/lib/jwt/decode.rb +10 -14
- data/lib/jwt/encoded_token.rb +71 -4
- data/lib/jwt/error.rb +0 -3
- data/lib/jwt/jwa/ecdsa.rb +0 -4
- data/lib/jwt/jwa/hmac.rb +0 -4
- data/lib/jwt/jwa/ps.rb +1 -0
- data/lib/jwt/jwa/rsa.rb +1 -0
- data/lib/jwt/jwa/signing_algorithm.rb +0 -1
- data/lib/jwt/jwa.rb +1 -26
- data/lib/jwt/jwk/ec.rb +1 -5
- data/lib/jwt/jwk/hmac.rb +3 -3
- data/lib/jwt/jwk/key_finder.rb +14 -1
- data/lib/jwt/jwk/rsa.rb +4 -1
- data/lib/jwt/jwk.rb +0 -1
- data/lib/jwt/token.rb +22 -3
- data/lib/jwt/version.rb +4 -20
- data/lib/jwt.rb +1 -7
- data/ruby-jwt.gemspec +1 -0
- metadata +19 -14
- data/lib/jwt/claims/verification_methods.rb +0 -20
- data/lib/jwt/claims_validator.rb +0 -18
- data/lib/jwt/deprecations.rb +0 -49
- data/lib/jwt/jwa/compat.rb +0 -32
- data/lib/jwt/jwa/eddsa.rb +0 -35
- data/lib/jwt/jwa/hmac_rbnacl.rb +0 -50
- data/lib/jwt/jwa/hmac_rbnacl_fixed.rb +0 -47
- data/lib/jwt/jwa/wrapper.rb +0 -44
- data/lib/jwt/jwk/okp_rbnacl.rb +0 -109
- data/lib/jwt/verify.rb +0 -40
data/lib/jwt/decode.rb
CHANGED
@@ -6,6 +6,11 @@ require 'jwt/x5c_key_finder'
|
|
6
6
|
module JWT
|
7
7
|
# The Decode class is responsible for decoding and verifying JWT tokens.
|
8
8
|
class Decode
|
9
|
+
# Order is very important - first check for string keys, next for symbols
|
10
|
+
ALGORITHM_KEYS = ['algorithm',
|
11
|
+
:algorithm,
|
12
|
+
'algorithms',
|
13
|
+
:algorithms].freeze
|
9
14
|
# Initializes a new Decode instance.
|
10
15
|
#
|
11
16
|
# @param jwt [String] the JWT to decode.
|
@@ -33,10 +38,10 @@ module JWT
|
|
33
38
|
verify_algo
|
34
39
|
set_key
|
35
40
|
verify_signature
|
36
|
-
Claims::DecodeVerifier.verify!(token.
|
41
|
+
Claims::DecodeVerifier.verify!(token.unverified_payload, @options)
|
37
42
|
end
|
38
43
|
|
39
|
-
[token.
|
44
|
+
[token.unverified_payload, token.header]
|
40
45
|
end
|
41
46
|
|
42
47
|
private
|
@@ -70,18 +75,9 @@ module JWT
|
|
70
75
|
@allowed_and_valid_algorithms ||= allowed_algorithms.select { |alg| alg.valid_alg?(alg_in_header) }
|
71
76
|
end
|
72
77
|
|
73
|
-
# Order is very important - first check for string keys, next for symbols
|
74
|
-
ALGORITHM_KEYS = ['algorithm',
|
75
|
-
:algorithm,
|
76
|
-
'algorithms',
|
77
|
-
:algorithms].freeze
|
78
|
-
|
79
78
|
def given_algorithms
|
80
|
-
ALGORITHM_KEYS.
|
81
|
-
|
82
|
-
return Array(alg) if alg
|
83
|
-
end
|
84
|
-
[]
|
79
|
+
alg_key = ALGORITHM_KEYS.find { |key| @options[key] }
|
80
|
+
Array(@options[alg_key])
|
85
81
|
end
|
86
82
|
|
87
83
|
def allowed_algorithms
|
@@ -93,7 +89,7 @@ module JWT
|
|
93
89
|
end
|
94
90
|
|
95
91
|
def find_key(&keyfinder)
|
96
|
-
key = (keyfinder.arity == 2 ? yield(token.header, token.
|
92
|
+
key = (keyfinder.arity == 2 ? yield(token.header, token.unverified_payload) : yield(token.header))
|
97
93
|
# key can be of type [string, nil, OpenSSL::PKey, Array]
|
98
94
|
return key if key && !Array(key).empty?
|
99
95
|
|
data/lib/jwt/encoded_token.rb
CHANGED
@@ -12,7 +12,21 @@ module JWT
|
|
12
12
|
# encoded_token.verify_signature!(algorithm: 'HS256', key: 'secret')
|
13
13
|
# encoded_token.payload # => {'pay' => 'load'}
|
14
14
|
class EncodedToken
|
15
|
-
|
15
|
+
# @private
|
16
|
+
# Allow access to the unverified payload for claim verification.
|
17
|
+
class ClaimsContext
|
18
|
+
extend Forwardable
|
19
|
+
|
20
|
+
def_delegators :@token, :header, :unverified_payload
|
21
|
+
|
22
|
+
def initialize(token)
|
23
|
+
@token = token
|
24
|
+
end
|
25
|
+
|
26
|
+
def payload
|
27
|
+
unverified_payload
|
28
|
+
end
|
29
|
+
end
|
16
30
|
|
17
31
|
# Returns the original token provided to the class.
|
18
32
|
# @return [String] The JWT token.
|
@@ -26,6 +40,7 @@ module JWT
|
|
26
40
|
raise ArgumentError, 'Provided JWT must be a String' unless jwt.is_a?(String)
|
27
41
|
|
28
42
|
@jwt = jwt
|
43
|
+
@signature_verified = false
|
29
44
|
@encoded_header, @encoded_payload, @encoded_signature = jwt.split('.')
|
30
45
|
end
|
31
46
|
|
@@ -53,11 +68,20 @@ module JWT
|
|
53
68
|
# @return [String] the encoded header.
|
54
69
|
attr_reader :encoded_header
|
55
70
|
|
56
|
-
# Returns the payload of the JWT token.
|
71
|
+
# Returns the payload of the JWT token. Access requires the signature to have been verified.
|
57
72
|
#
|
58
73
|
# @return [Hash] the payload.
|
74
|
+
# @raise [JWT::DecodeError] if the signature has not been verified.
|
59
75
|
def payload
|
60
|
-
|
76
|
+
raise JWT::DecodeError, 'Verify the token signature before accessing the payload' unless @signature_verified
|
77
|
+
|
78
|
+
decoded_payload
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the payload of the JWT token without requiring the signature to have been verified.
|
82
|
+
# @return [Hash] the payload.
|
83
|
+
def unverified_payload
|
84
|
+
decoded_payload
|
61
85
|
end
|
62
86
|
|
63
87
|
# Sets or returns the encoded payload of the JWT token.
|
@@ -72,6 +96,22 @@ module JWT
|
|
72
96
|
[encoded_header, encoded_payload].join('.')
|
73
97
|
end
|
74
98
|
|
99
|
+
# Verifies the token signature and claims.
|
100
|
+
# By default it verifies the 'exp' claim.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# encoded_token.verify!(signature: { algorithm: 'HS256', key: 'secret' }, claims: [:exp])
|
104
|
+
#
|
105
|
+
# @param signature [Hash] the parameters for signature verification (see {#verify_signature!}).
|
106
|
+
# @param claims [Array<Symbol>, Hash] the claims to verify (see {#verify_claims!}).
|
107
|
+
# @return [nil]
|
108
|
+
# @raise [JWT::DecodeError] if the signature or claim verification fails.
|
109
|
+
def verify!(signature:, claims: [:exp])
|
110
|
+
verify_signature!(**signature)
|
111
|
+
claims.is_a?(Array) ? verify_claims!(*claims) : verify_claims!(claims)
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
|
75
115
|
# Verifies the signature of the JWT token.
|
76
116
|
#
|
77
117
|
# @param algorithm [String, Array<String>, Object, Array<Object>] the algorithm(s) to use for verification.
|
@@ -96,11 +136,34 @@ module JWT
|
|
96
136
|
# @param key [String, Array<String>] the key(s) to use for verification.
|
97
137
|
# @return [Boolean] true if the signature is valid, false otherwise.
|
98
138
|
def valid_signature?(algorithm:, key:)
|
99
|
-
Array(JWA.resolve_and_sort(algorithms: algorithm, preferred_algorithm: header['alg'])).any? do |algo|
|
139
|
+
valid = Array(JWA.resolve_and_sort(algorithms: algorithm, preferred_algorithm: header['alg'])).any? do |algo|
|
100
140
|
Array(key).any? do |one_key|
|
101
141
|
algo.verify(data: signing_input, signature: signature, verification_key: one_key)
|
102
142
|
end
|
103
143
|
end
|
144
|
+
|
145
|
+
valid.tap { |verified| @signature_verified = verified }
|
146
|
+
end
|
147
|
+
|
148
|
+
# Verifies the claims of the token.
|
149
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
150
|
+
# @raise [JWT::DecodeError] if the claims are invalid.
|
151
|
+
def verify_claims!(*options)
|
152
|
+
Claims::Verifier.verify!(ClaimsContext.new(self), *options)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Returns the errors of the claims of the token.
|
156
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
157
|
+
# @return [Array<Symbol>] the errors of the claims.
|
158
|
+
def claim_errors(*options)
|
159
|
+
Claims::Verifier.errors(ClaimsContext.new(self), *options)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns whether the claims of the token are valid.
|
163
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
164
|
+
# @return [Boolean] whether the claims are valid.
|
165
|
+
def valid_claims?(*options)
|
166
|
+
claim_errors(*options).empty?
|
104
167
|
end
|
105
168
|
|
106
169
|
alias to_s jwt
|
@@ -135,5 +198,9 @@ module JWT
|
|
135
198
|
rescue ::JSON::ParserError
|
136
199
|
raise JWT::DecodeError, 'Invalid segment encoding'
|
137
200
|
end
|
201
|
+
|
202
|
+
def decoded_payload
|
203
|
+
@decoded_payload ||= decode_payload
|
204
|
+
end
|
138
205
|
end
|
139
206
|
end
|
data/lib/jwt/error.rb
CHANGED
@@ -7,9 +7,6 @@ module JWT
|
|
7
7
|
# The DecodeError class is raised when there is an error decoding a JWT.
|
8
8
|
class DecodeError < StandardError; end
|
9
9
|
|
10
|
-
# The RequiredDependencyError class is raised when a required dependency is missing.
|
11
|
-
class RequiredDependencyError < StandardError; end
|
12
|
-
|
13
10
|
# The VerificationError class is raised when there is an error verifying a JWT.
|
14
11
|
class VerificationError < DecodeError; end
|
15
12
|
|
data/lib/jwt/jwa/ecdsa.rb
CHANGED
@@ -56,10 +56,6 @@ module JWT
|
|
56
56
|
register_algorithm(new(v[:algorithm], v[:digest]))
|
57
57
|
end
|
58
58
|
|
59
|
-
def self.from_algorithm(algorithm)
|
60
|
-
new(algorithm, algorithm.downcase.gsub('es', 'sha'))
|
61
|
-
end
|
62
|
-
|
63
59
|
def self.curve_by_name(name)
|
64
60
|
NAMED_CURVES.fetch(name) do
|
65
61
|
raise UnsupportedEcdsaCurve, "The ECDSA curve '#{name}' is not supported"
|
data/lib/jwt/jwa/hmac.rb
CHANGED
data/lib/jwt/jwa/ps.rb
CHANGED
@@ -13,6 +13,7 @@ module JWT
|
|
13
13
|
|
14
14
|
def sign(data:, signing_key:)
|
15
15
|
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance.") unless signing_key.is_a?(::OpenSSL::PKey::RSA)
|
16
|
+
raise_sign_error!('The key length must be greater than or equal to 2048 bits') if signing_key.n.num_bits < 2048
|
16
17
|
|
17
18
|
signing_key.sign_pss(digest_algorithm, data, salt_length: :digest, mgf1_hash: digest_algorithm)
|
18
19
|
end
|
data/lib/jwt/jwa/rsa.rb
CHANGED
@@ -13,6 +13,7 @@ module JWT
|
|
13
13
|
|
14
14
|
def sign(data:, signing_key:)
|
15
15
|
raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance") unless signing_key.is_a?(OpenSSL::PKey::RSA)
|
16
|
+
raise_sign_error!('The key length must be greater than or equal to 2048 bits') if signing_key.n.num_bits < 2048
|
16
17
|
|
17
18
|
signing_key.sign(digest, data)
|
18
19
|
end
|
data/lib/jwt/jwa.rb
CHANGED
@@ -2,13 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'openssl'
|
4
4
|
|
5
|
-
begin
|
6
|
-
require 'rbnacl'
|
7
|
-
rescue LoadError
|
8
|
-
raise if defined?(RbNaCl)
|
9
|
-
end
|
10
|
-
|
11
|
-
require_relative 'jwa/compat'
|
12
5
|
require_relative 'jwa/signing_algorithm'
|
13
6
|
require_relative 'jwa/ecdsa'
|
14
7
|
require_relative 'jwa/hmac'
|
@@ -16,15 +9,6 @@ require_relative 'jwa/none'
|
|
16
9
|
require_relative 'jwa/ps'
|
17
10
|
require_relative 'jwa/rsa'
|
18
11
|
require_relative 'jwa/unsupported'
|
19
|
-
require_relative 'jwa/wrapper'
|
20
|
-
|
21
|
-
require_relative 'jwa/eddsa' if JWT.rbnacl?
|
22
|
-
|
23
|
-
if JWT.rbnacl_6_or_greater?
|
24
|
-
require_relative 'jwa/hmac_rbnacl'
|
25
|
-
elsif JWT.rbnacl?
|
26
|
-
require_relative 'jwa/hmac_rbnacl_fixed'
|
27
|
-
end
|
28
12
|
|
29
13
|
module JWT
|
30
14
|
# The JWA module contains all supported algorithms.
|
@@ -34,10 +18,7 @@ module JWT
|
|
34
18
|
def resolve(algorithm)
|
35
19
|
return find(algorithm) if algorithm.is_a?(String) || algorithm.is_a?(Symbol)
|
36
20
|
|
37
|
-
unless algorithm.is_a?(SigningAlgorithm)
|
38
|
-
Deprecations.warning('Custom algorithms are required to include JWT::JWA::SigningAlgorithm. Custom algorithms that do not include this module may stop working in the next major version of ruby-jwt.')
|
39
|
-
return Wrapper.new(algorithm)
|
40
|
-
end
|
21
|
+
raise ArgumentError, 'Custom algorithms are required to include JWT::JWA::SigningAlgorithm' unless algorithm.is_a?(SigningAlgorithm)
|
41
22
|
|
42
23
|
algorithm
|
43
24
|
end
|
@@ -47,12 +28,6 @@ module JWT
|
|
47
28
|
algs = Array(algorithms).map { |alg| JWA.resolve(alg) }
|
48
29
|
algs.partition { |alg| alg.valid_alg?(preferred_algorithm) }.flatten
|
49
30
|
end
|
50
|
-
|
51
|
-
# @deprecated The `::JWT::JWA.create` method is deprecated and will be removed in the next major version of ruby-jwt.
|
52
|
-
def create(algorithm)
|
53
|
-
Deprecations.warning('The ::JWT::JWA.create method is deprecated and will be removed in the next major version of ruby-jwt.')
|
54
|
-
resolve(algorithm)
|
55
|
-
end
|
56
31
|
end
|
57
32
|
end
|
58
33
|
end
|
data/lib/jwt/jwk/ec.rb
CHANGED
@@ -68,7 +68,7 @@ module JWT
|
|
68
68
|
def []=(key, value)
|
69
69
|
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if EC_KEY_ELEMENTS.include?(key.to_sym)
|
70
70
|
|
71
|
-
super
|
71
|
+
super
|
72
72
|
end
|
73
73
|
|
74
74
|
private
|
@@ -124,10 +124,6 @@ module JWT
|
|
124
124
|
::JWT::Base64.url_encode(octets)
|
125
125
|
end
|
126
126
|
|
127
|
-
def encode_open_ssl_bn(key_part)
|
128
|
-
::JWT::Base64.url_encode(key_part.to_s(BINARY))
|
129
|
-
end
|
130
|
-
|
131
127
|
def parse_ec_key(key)
|
132
128
|
crv, x_octets, y_octets = keypair_components(key)
|
133
129
|
octets = key.private_key&.to_bn&.to_s(BINARY)
|
data/lib/jwt/jwk/hmac.rb
CHANGED
@@ -64,13 +64,13 @@ module JWT
|
|
64
64
|
def []=(key, value)
|
65
65
|
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if HMAC_KEY_ELEMENTS.include?(key.to_sym)
|
66
66
|
|
67
|
-
super
|
67
|
+
super
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
71
71
|
|
72
72
|
def secret
|
73
|
-
self[:k]
|
73
|
+
@secret ||= ::JWT::Base64.url_decode(self[:k])
|
74
74
|
end
|
75
75
|
|
76
76
|
def extract_key_params(key)
|
@@ -78,7 +78,7 @@ module JWT
|
|
78
78
|
when JWT::JWK::HMAC
|
79
79
|
key.export(include_private: true)
|
80
80
|
when String # Accept String key as input
|
81
|
-
{ kty: KTY, k: key }
|
81
|
+
{ kty: KTY, k: ::JWT::Base64.url_encode(key) }
|
82
82
|
when Hash
|
83
83
|
key.transform_keys(&:to_sym)
|
84
84
|
else
|
data/lib/jwt/jwk/key_finder.rb
CHANGED
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
module JWT
|
4
4
|
module JWK
|
5
|
-
#
|
5
|
+
# JSON Web Key keyfinder
|
6
|
+
# To find the key for a given kid
|
6
7
|
class KeyFinder
|
8
|
+
# Initializes a new KeyFinder instance.
|
9
|
+
# @param [Hash] options the options to create a KeyFinder with
|
10
|
+
# @option options [Proc, JWT::JWK::Set] :jwks the jwks or a loader proc
|
11
|
+
# @option options [Boolean] :allow_nil_kid whether to allow nil kid
|
7
12
|
def initialize(options)
|
8
13
|
@allow_nil_kid = options[:allow_nil_kid]
|
9
14
|
jwks_or_loader = options[:jwks]
|
@@ -15,6 +20,8 @@ module JWT
|
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
23
|
+
# Returns the verification key for the given kid
|
24
|
+
# @param [String] kid the key id
|
18
25
|
def key_for(kid)
|
19
26
|
raise ::JWT::DecodeError, 'No key id (kid) found from token headers' unless kid || @allow_nil_kid
|
20
27
|
raise ::JWT::DecodeError, 'Invalid type for kid header parameter' unless kid.nil? || kid.is_a?(String)
|
@@ -27,6 +34,12 @@ module JWT
|
|
27
34
|
jwk.verify_key
|
28
35
|
end
|
29
36
|
|
37
|
+
# Returns the key for the given token
|
38
|
+
# @param [JWT::EncodedToken] token the token
|
39
|
+
def call(token)
|
40
|
+
key_for(token.header['kid'])
|
41
|
+
end
|
42
|
+
|
30
43
|
private
|
31
44
|
|
32
45
|
def resolve_key(kid)
|
data/lib/jwt/jwk/rsa.rb
CHANGED
@@ -67,7 +67,7 @@ module JWT
|
|
67
67
|
def []=(key, value)
|
68
68
|
raise ArgumentError, 'cannot overwrite cryptographic key attributes' if RSA_KEY_ELEMENTS.include?(key.to_sym)
|
69
69
|
|
70
|
-
super
|
70
|
+
super
|
71
71
|
end
|
72
72
|
|
73
73
|
private
|
@@ -165,6 +165,8 @@ module JWT
|
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
|
+
# :nocov:
|
169
|
+
# Before openssl 2.0, we need to use the accessors to set the key
|
168
170
|
def create_rsa_key_using_accessors(rsa_parameters) # rubocop:disable Metrics/AbcSize
|
169
171
|
validate_rsa_parameters!(rsa_parameters)
|
170
172
|
|
@@ -179,6 +181,7 @@ module JWT
|
|
179
181
|
rsa_key.iqmp = rsa_parameters[:qi] if rsa_parameters[:qi]
|
180
182
|
end
|
181
183
|
end
|
184
|
+
# :nocov:
|
182
185
|
|
183
186
|
def validate_rsa_parameters!(rsa_parameters)
|
184
187
|
return unless rsa_parameters.key?(:d)
|
data/lib/jwt/jwk.rb
CHANGED
data/lib/jwt/token.rb
CHANGED
@@ -15,8 +15,6 @@ module JWT
|
|
15
15
|
# token.header # => {"custom"=>"value", "alg"=>"HS256"}
|
16
16
|
#
|
17
17
|
class Token
|
18
|
-
include Claims::VerificationMethods
|
19
|
-
|
20
18
|
# Initializes a new Token instance.
|
21
19
|
#
|
22
20
|
# @param header [Hash] the header of the JWT token.
|
@@ -97,13 +95,34 @@ module JWT
|
|
97
95
|
raise ::JWT::EncodeError, 'Token already signed' if @signature
|
98
96
|
|
99
97
|
JWA.resolve(algorithm).tap do |algo|
|
100
|
-
header.merge!(algo.header)
|
98
|
+
header.merge!(algo.header) { |_key, old, _new| old }
|
101
99
|
@signature = algo.sign(data: signing_input, signing_key: key)
|
102
100
|
end
|
103
101
|
|
104
102
|
nil
|
105
103
|
end
|
106
104
|
|
105
|
+
# Verifies the claims of the token.
|
106
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
107
|
+
# @raise [JWT::DecodeError] if the claims are invalid.
|
108
|
+
def verify_claims!(*options)
|
109
|
+
Claims::Verifier.verify!(self, *options)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the errors of the claims of the token.
|
113
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
114
|
+
# @return [Array<Symbol>] the errors of the claims.
|
115
|
+
def claim_errors(*options)
|
116
|
+
Claims::Verifier.errors(self, *options)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns whether the claims of the token are valid.
|
120
|
+
# @param options [Array<Symbol>, Hash] the claims to verify.
|
121
|
+
# @return [Boolean] whether the claims are valid.
|
122
|
+
def valid_claims?(*options)
|
123
|
+
claim_errors(*options).empty?
|
124
|
+
end
|
125
|
+
|
107
126
|
# Returns the JWT token as a string.
|
108
127
|
#
|
109
128
|
# @return [String] the JWT token as a string.
|
data/lib/jwt/version.rb
CHANGED
@@ -12,11 +12,11 @@ module JWT
|
|
12
12
|
Gem::Version.new(VERSION::STRING)
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Version constants
|
16
16
|
module VERSION
|
17
|
-
MAJOR =
|
18
|
-
MINOR =
|
19
|
-
TINY =
|
17
|
+
MAJOR = 3
|
18
|
+
MINOR = 0
|
19
|
+
TINY = 0
|
20
20
|
PRE = nil
|
21
21
|
|
22
22
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
@@ -32,22 +32,6 @@ module JWT
|
|
32
32
|
true if 3 * 0x10000000 <= OpenSSL::OPENSSL_VERSION_NUMBER
|
33
33
|
end
|
34
34
|
|
35
|
-
# Checks if the RbNaCl library is defined.
|
36
|
-
#
|
37
|
-
# @return [Boolean] true if RbNaCl is defined, false otherwise.
|
38
|
-
# @api private
|
39
|
-
def self.rbnacl?
|
40
|
-
defined?(::RbNaCl)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Checks if the RbNaCl library version is 6.0.0 or greater.
|
44
|
-
#
|
45
|
-
# @return [Boolean] true if RbNaCl version is 6.0.0 or greater, false otherwise.
|
46
|
-
# @api private
|
47
|
-
def self.rbnacl_6_or_greater?
|
48
|
-
rbnacl? && ::Gem::Version.new(::RbNaCl::VERSION) >= ::Gem::Version.new('6.0.0')
|
49
|
-
end
|
50
|
-
|
51
35
|
# Checks if there is an OpenSSL 3 HMAC empty key regression.
|
52
36
|
#
|
53
37
|
# @return [Boolean] true if there is an OpenSSL 3 HMAC empty key regression, false otherwise.
|
data/lib/jwt.rb
CHANGED
@@ -5,7 +5,6 @@ require 'jwt/base64'
|
|
5
5
|
require 'jwt/json'
|
6
6
|
require 'jwt/decode'
|
7
7
|
require 'jwt/configuration'
|
8
|
-
require 'jwt/deprecations'
|
9
8
|
require 'jwt/encode'
|
10
9
|
require 'jwt/error'
|
11
10
|
require 'jwt/jwk'
|
@@ -13,9 +12,6 @@ require 'jwt/claims'
|
|
13
12
|
require 'jwt/encoded_token'
|
14
13
|
require 'jwt/token'
|
15
14
|
|
16
|
-
require 'jwt/claims_validator'
|
17
|
-
require 'jwt/verify'
|
18
|
-
|
19
15
|
# JSON Web Token implementation
|
20
16
|
#
|
21
17
|
# Should be up to date with the latest spec:
|
@@ -47,8 +43,6 @@ module JWT
|
|
47
43
|
# @param options [Hash] additional options for decoding.
|
48
44
|
# @return [Array<Hash>] the decoded payload and headers.
|
49
45
|
def decode(jwt, key = nil, verify = true, options = {}, &keyfinder) # rubocop:disable Style/OptionalBooleanParameter
|
50
|
-
|
51
|
-
Decode.new(jwt, key, verify, configuration.decode.to_h.merge(options), &keyfinder).decode_segments
|
52
|
-
end
|
46
|
+
Decode.new(jwt, key, verify, configuration.decode.to_h.merge(options), &keyfinder).decode_segments
|
53
47
|
end
|
54
48
|
end
|
data/ruby-jwt.gemspec
CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
|
36
36
|
spec.add_development_dependency 'appraisal'
|
37
37
|
spec.add_development_dependency 'bundler'
|
38
|
+
spec.add_development_dependency 'logger'
|
38
39
|
spec.add_development_dependency 'rake'
|
39
40
|
spec.add_development_dependency 'rspec'
|
40
41
|
spec.add_development_dependency 'rubocop'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jwt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Rudat
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: base64
|
@@ -51,6 +51,20 @@ dependencies:
|
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: logger
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
54
68
|
- !ruby/object:Gem::Dependency
|
55
69
|
name: rake
|
56
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,6 +134,7 @@ files:
|
|
120
134
|
- CONTRIBUTING.md
|
121
135
|
- LICENSE
|
122
136
|
- README.md
|
137
|
+
- UPGRADING.md
|
123
138
|
- lib/jwt.rb
|
124
139
|
- lib/jwt/base64.rb
|
125
140
|
- lib/jwt/claims.rb
|
@@ -134,44 +149,34 @@ files:
|
|
134
149
|
- lib/jwt/claims/numeric.rb
|
135
150
|
- lib/jwt/claims/required.rb
|
136
151
|
- lib/jwt/claims/subject.rb
|
137
|
-
- lib/jwt/claims/verification_methods.rb
|
138
152
|
- lib/jwt/claims/verifier.rb
|
139
|
-
- lib/jwt/claims_validator.rb
|
140
153
|
- lib/jwt/configuration.rb
|
141
154
|
- lib/jwt/configuration/container.rb
|
142
155
|
- lib/jwt/configuration/decode_configuration.rb
|
143
156
|
- lib/jwt/configuration/jwk_configuration.rb
|
144
157
|
- lib/jwt/decode.rb
|
145
|
-
- lib/jwt/deprecations.rb
|
146
158
|
- lib/jwt/encode.rb
|
147
159
|
- lib/jwt/encoded_token.rb
|
148
160
|
- lib/jwt/error.rb
|
149
161
|
- lib/jwt/json.rb
|
150
162
|
- lib/jwt/jwa.rb
|
151
|
-
- lib/jwt/jwa/compat.rb
|
152
163
|
- lib/jwt/jwa/ecdsa.rb
|
153
|
-
- lib/jwt/jwa/eddsa.rb
|
154
164
|
- lib/jwt/jwa/hmac.rb
|
155
|
-
- lib/jwt/jwa/hmac_rbnacl.rb
|
156
|
-
- lib/jwt/jwa/hmac_rbnacl_fixed.rb
|
157
165
|
- lib/jwt/jwa/none.rb
|
158
166
|
- lib/jwt/jwa/ps.rb
|
159
167
|
- lib/jwt/jwa/rsa.rb
|
160
168
|
- lib/jwt/jwa/signing_algorithm.rb
|
161
169
|
- lib/jwt/jwa/unsupported.rb
|
162
|
-
- lib/jwt/jwa/wrapper.rb
|
163
170
|
- lib/jwt/jwk.rb
|
164
171
|
- lib/jwt/jwk/ec.rb
|
165
172
|
- lib/jwt/jwk/hmac.rb
|
166
173
|
- lib/jwt/jwk/key_base.rb
|
167
174
|
- lib/jwt/jwk/key_finder.rb
|
168
175
|
- lib/jwt/jwk/kid_as_key_digest.rb
|
169
|
-
- lib/jwt/jwk/okp_rbnacl.rb
|
170
176
|
- lib/jwt/jwk/rsa.rb
|
171
177
|
- lib/jwt/jwk/set.rb
|
172
178
|
- lib/jwt/jwk/thumbprint.rb
|
173
179
|
- lib/jwt/token.rb
|
174
|
-
- lib/jwt/verify.rb
|
175
180
|
- lib/jwt/version.rb
|
176
181
|
- lib/jwt/x5c_key_finder.rb
|
177
182
|
- ruby-jwt.gemspec
|
@@ -180,7 +185,7 @@ licenses:
|
|
180
185
|
- MIT
|
181
186
|
metadata:
|
182
187
|
bug_tracker_uri: https://github.com/jwt/ruby-jwt/issues
|
183
|
-
changelog_uri: https://github.com/jwt/ruby-jwt/blob/
|
188
|
+
changelog_uri: https://github.com/jwt/ruby-jwt/blob/v3.0.0/CHANGELOG.md
|
184
189
|
rubygems_mfa_required: 'true'
|
185
190
|
rdoc_options: []
|
186
191
|
require_paths:
|
@@ -196,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
201
|
- !ruby/object:Gem::Version
|
197
202
|
version: '0'
|
198
203
|
requirements: []
|
199
|
-
rubygems_version: 3.6.
|
204
|
+
rubygems_version: 3.6.7
|
200
205
|
specification_version: 4
|
201
206
|
summary: JSON Web Token implementation in Ruby
|
202
207
|
test_files: []
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module JWT
|
4
|
-
module Claims
|
5
|
-
# @api private
|
6
|
-
module VerificationMethods
|
7
|
-
def verify_claims!(*options)
|
8
|
-
Verifier.verify!(self, *options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def claim_errors(*options)
|
12
|
-
Verifier.errors(self, *options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def valid_claims?(*options)
|
16
|
-
claim_errors(*options).empty?
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/jwt/claims_validator.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module JWT
|
4
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
5
|
-
class ClaimsValidator
|
6
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
7
|
-
def initialize(payload)
|
8
|
-
Deprecations.warning('The ::JWT::ClaimsValidator class is deprecated and will be removed in the next major version of ruby-jwt')
|
9
|
-
@payload = payload
|
10
|
-
end
|
11
|
-
|
12
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
13
|
-
def validate!
|
14
|
-
Claims.verify_payload!(@payload, :numeric)
|
15
|
-
true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|