Class: JWT::Claims::Required
- Inherits:
-
Object
- Object
- JWT::Claims::Required
- Defined in:
- lib/jwt/claims/required.rb
Overview
The Required class is responsible for validating that all required claims are present in a JWT token.
Instance Method Summary collapse
-
#initialize(required_claims:) ⇒ Required
constructor
Initializes a new Required instance.
-
#verify!(context:, **_args) ⇒ nil
Verifies that all required claims are present in the JWT payload.
Constructor Details
#initialize(required_claims:) ⇒ Required
Initializes a new Required instance.
10 11 12 |
# File 'lib/jwt/claims/required.rb', line 10 def initialize(required_claims:) @required_claims = required_claims end |
Instance Method Details
#verify!(context:, **_args) ⇒ nil
Verifies that all required claims are present in the JWT payload.
20 21 22 23 24 25 26 |
# File 'lib/jwt/claims/required.rb', line 20 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 |