Sha256: 1b310afefbfa797a9c1b2c09c448f98bc9398f6120dc4f1deef1a79d2ce0c196

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module JWT
  module Claims
    # Responsible of validation the crit header
    class Crit
      # Initializes a new Crit instance.
      #
      # @param expected_crits [String] the expected crit header values for the JWT token.
      def initialize(expected_crits:)
        @expected_crits = Array(expected_crits)
      end

      # 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]
      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

      private

      attr_reader :expected_crits
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/jwt-2.10.1/lib/jwt/claims/crit.rb
jwt-2.10.1 lib/jwt/claims/crit.rb
jwt-2.10.0 lib/jwt/claims/crit.rb