class JWT::Claims::Crit

Responsible of validation the crit header

Attributes

expected_crits[R]

Public Class Methods

new(expected_crits:) click to toggle source

Initializes a new Crit instance.

@param expected_crits [String] the expected crit header values for the JWT token.

# File lib/jwt/claims/crit.rb, line 10
def initialize(expected_crits:)
  @expected_crits = Array(expected_crits)
end

Public Instance Methods

verify!(context:, **_args) click to toggle source

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

@param context [Object] the context containing the JWT payload and header. @param _args [Hash] additional arguments (not used). @raise [JWT::InvalidCritError] if the crit claim is invalid. @return [nil]

# 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