Sha256: deb9536c052ffb76c3bb8e7e92b086c84d8860067a4096a881d6f2a3923b4185

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module JWT
  module Claims
    # The Required class is responsible for validating that all required claims are present in a JWT token.
    class Required
      # Initializes a new Required instance.
      #
      # @param required_claims [Array<String>] the list of required claims.
      def initialize(required_claims:)
        @required_claims = required_claims
      end

      # Verifies that all required claims are present in the JWT payload.
      #
      # @param context [Object] the context containing the JWT payload.
      # @param _args [Hash] additional arguments (not used).
      # @raise [JWT::MissingRequiredClaim] if any required claim is missing.
      # @return [nil]
      def verify!(context:, **_args)
        required_claims.each do |required_claim|
          next if context.payload.is_a?(Hash) && context.payload.key?(required_claim)

          raise JWT::MissingRequiredClaim, "Missing required claim #{required_claim}"
        end
      end

      private

      attr_reader :required_claims
    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/required.rb
jwt-2.10.1 lib/jwt/claims/required.rb
jwt-2.10.0 lib/jwt/claims/required.rb