Class: JWT::Claims::IssuedAt

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/claims/issued_at.rb

Overview

The IssuedAt class is responsible for validating the issued at claim ('iat') in a JWT token.

Instance Method Summary collapse

Constructor Details

#initialize(leeway: 0) ⇒ IssuedAt

Initializes a new IssuedAt instance.

Parameters:

  • leeway (Integer) (defaults to: 0)

    the drift (in seconds) to allow between the clock of the issuer and the clock of the verifier. Default: 0.



10
11
12
# File 'lib/jwt/claims/issued_at.rb', line 10

def initialize(leeway: 0)
  @leeway = leeway || 0
end

Instance Method Details

#verify!(context:, **_args) ⇒ nil

Verifies the issued at claim ('iat') in the JWT token.

Parameters:

  • context (Object)

    the context containing the JWT payload.

  • _args (Hash)

    additional arguments (not used).

Returns:

  • (nil)

Raises:



20
21
22
23
24
25
26
# File 'lib/jwt/claims/issued_at.rb', line 20

def verify!(context:, **_args)
  return unless context.payload.is_a?(Hash)
  return unless context.payload.key?('iat')

  iat = context.payload['iat']
  raise(JWT::InvalidIatError, 'Invalid iat') if !iat.is_a?(::Numeric) || iat.to_f > (Time.now.to_f + leeway)
end