Class: JWT::Claims::NotBefore

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

Overview

The NotBefore class is responsible for validating the ‘nbf’ (Not Before) claim in a JWT token.

Instance Method Summary collapse

Constructor Details

#initialize(leeway:) ⇒ NotBefore

Initializes a new NotBefore instance.

Parameters:

  • leeway (Integer)

    the amount of leeway (in seconds) to allow when validating the ‘nbf’ claim. Defaults to 0.



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

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

Instance Method Details

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

Verifies the ‘nbf’ (Not Before) claim 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
# File 'lib/jwt/claims/not_before.rb', line 20

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

  raise JWT::ImmatureSignature, 'Signature nbf has not been reached' if context.payload['nbf'].to_i > (Time.now.to_i + leeway)
end