Class: JWT::Claims::Crit

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

Overview

Responsible of validation the crit header

Instance Method Summary collapse

Constructor Details

#initialize(expected_crits:) ⇒ Crit

Initializes a new Crit instance.

Parameters:

  • expected_crits (String)

    the expected crit header values for the JWT token.



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

def initialize(expected_crits:)
  @expected_crits = Array(expected_crits)
end

Instance Method Details

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

Verifies the critical claim (‘crit’) in the JWT token header.

Parameters:

  • context (Object)

    the context containing the JWT payload and header.

  • _args (Hash)

    additional arguments (not used).

Returns:

  • (nil)

Raises:



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

def verify!(context:, **_args)
  raise(JWT::InvalidCritError, 'Crit header missing') unless context.header['crit']
  raise(JWT::InvalidCritError, 'Crit header should be an array') unless context.header['crit'].is_a?(Array)

  missing = (expected_crits - context.header['crit'])
  raise(JWT::InvalidCritError, "Crit header missing expected values: #{missing.join(', ')}") if missing.any?

  nil
end