Sha256: ad015c4c55f1803d50ca9e7a8e2591d3a3bab1ba3729ba84b07f5ce89f3080cb

Contents?: true

Size: 686 Bytes

Versions: 8

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

require_relative './error'

module JWT
  class ClaimsValidator
    NUMERIC_CLAIMS = %i[
      exp
      iat
      nbf
    ].freeze

    def initialize(payload)
      @payload = payload.transform_keys(&:to_sym)
    end

    def validate!
      validate_numeric_claims

      true
    end

    private

    def validate_numeric_claims
      NUMERIC_CLAIMS.each do |claim|
        validate_is_numeric(claim) if @payload.key?(claim)
      end
    end

    def validate_is_numeric(claim)
      return if @payload[claim].is_a?(Numeric)

      raise InvalidPayload, "#{claim} claim must be a Numeric value but it is a #{@payload[claim].class}"
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
jwt-2.7.1 lib/jwt/claims_validator.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/jwt-2.7.0/lib/jwt/claims_validator.rb
jwt-2.7.0 lib/jwt/claims_validator.rb
jwt-2.6.0 lib/jwt/claims_validator.rb
jwt-2.5.0 lib/jwt/claims_validator.rb
jwt-2.4.1 lib/jwt/claims_validator.rb
jwt-2.4.0 lib/jwt/claims_validator.rb
jwt-2.4.0.beta1 lib/jwt/claims_validator.rb