Class: JWT::Claims::Required

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/claims/required.rb

Instance Method Summary collapse

Constructor Details

#initialize(required_claims:) ⇒ Required

Returns a new instance of Required.



6
7
8
# File 'lib/jwt/claims/required.rb', line 6

def initialize(required_claims:)
  @required_claims = required_claims
end

Instance Method Details

#verify!(context:, **_args) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/jwt/claims/required.rb', line 10

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