Class: JWT::Claims::JwtId
- Inherits:
-
Object
- Object
- JWT::Claims::JwtId
- Defined in:
- lib/jwt/claims/jwt_id.rb
Overview
The JwtId class is responsible for validating the JWT ID claim (‘jti’) in a JWT token.
Instance Method Summary collapse
-
#initialize(validator:) ⇒ JwtId
constructor
Initializes a new JwtId instance.
-
#verify!(context:, **_args) ⇒ nil
Verifies the JWT ID claim (‘jti’) in the JWT token.
Constructor Details
#initialize(validator:) ⇒ JwtId
Initializes a new JwtId instance.
10 11 12 |
# File 'lib/jwt/claims/jwt_id.rb', line 10 def initialize(validator:) @validator = validator end |
Instance Method Details
#verify!(context:, **_args) ⇒ nil
Verifies the JWT ID claim (‘jti’) in the JWT token.
20 21 22 23 24 25 26 27 28 |
# File 'lib/jwt/claims/jwt_id.rb', line 20 def verify!(context:, **_args) jti = context.payload['jti'] if validator.respond_to?(:call) verified = validator.arity == 2 ? validator.call(jti, context.payload) : validator.call(jti) raise(JWT::InvalidJtiError, 'Invalid jti') unless verified elsif jti.to_s.strip.empty? raise(JWT::InvalidJtiError, 'Missing jti') end end |