Sha256: c4947141347948f6cd31423e8ac510b75fdb5c34b8bcf10ec8553c0f03b10ee4

Contents?: true

Size: 652 Bytes

Versions: 4

Compression:

Stored size: 652 Bytes

Contents

require_relative './error'

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

    def initialize(payload)
      @payload = payload.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
    end

    def validate!
      validate_int_claims

      true
    end

    private

    def validate_int_claims
      INTEGER_CLAIMS.each do |claim|
        validate_is_int(claim) if @payload.key?(claim)
      end
    end

    def validate_is_int(claim)
      raise InvalidPayload, "#{claim} claim must be an Integer but it is a #{@payload[claim].class}" unless @payload[claim].is_a?(Integer)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jwt-2.2.2 lib/jwt/claims_validator.rb
jwt-2.2.1 lib/jwt/claims_validator.rb
jwt-2.2.0 lib/jwt/claims_validator.rb
jwt-2.2.0.pre.beta.0 lib/jwt/claims_validator.rb