Class: JWT::Claims::Expiration
- Inherits:
-
Object
- Object
- JWT::Claims::Expiration
- Defined in:
- lib/jwt/claims/expiration.rb
Overview
The Expiration class is responsible for validating the expiration claim (‘exp’) in a JWT token.
Instance Method Summary collapse
-
#initialize(leeway:) ⇒ Expiration
constructor
Initializes a new Expiration instance.
-
#verify!(context:, **_args) ⇒ nil
Verifies the expiration claim (‘exp’) in the JWT token.
Constructor Details
#initialize(leeway:) ⇒ Expiration
Initializes a new Expiration instance.
10 11 12 |
# File 'lib/jwt/claims/expiration.rb', line 10 def initialize(leeway:) @leeway = leeway || 0 end |
Instance Method Details
#verify!(context:, **_args) ⇒ nil
Verifies the expiration claim (‘exp’) in the JWT token.
20 21 22 23 24 25 |
# File 'lib/jwt/claims/expiration.rb', line 20 def verify!(context:, **_args) return unless context.payload.is_a?(Hash) return unless context.payload.key?('exp') raise JWT::ExpiredSignature, 'Signature has expired' if context.payload['exp'].to_i <= (Time.now.to_i - leeway) end |