lib/jwt_keeper/token.rb in jwt_keeper-4.0.0 vs lib/jwt_keeper/token.rb in jwt_keeper-4.0.1
- old
+ new
@@ -13,10 +13,11 @@
@claims = {
nbf: DateTime.now.to_i, # not before
iat: DateTime.now.to_i, # issued at
jti: SecureRandom.uuid # JWT ID
}
+
@claims.merge!(JWTKeeper.configuration.base_claims)
@claims.merge!(private_claims)
@claims[:exp] = @claims[:exp].to_i if @claims[:exp].is_a?(Time)
end
@@ -34,11 +35,13 @@
# @return [Token] token object
def self.find(raw_token, cookie_secret = nil)
claims = decode(raw_token, cookie_secret)
return nil if claims.nil?
- new_token = new(claims, cookie_secret)
+ new_token = new({}, cookie_secret)
+ new_token.claims = claims
+
return nil if new_token.revoked?
new_token
end
# Sets a token to the pending rotation state. The expire is set to the maxium possible time but
@@ -150,10 +153,10 @@
private
# @!visibility private
def encode
- JWT.encode(claims,
+ JWT.encode(claims.compact,
JWTKeeper.configuration.secret.to_s + cookie_secret.to_s,
JWTKeeper.configuration.algorithm
)
end
end