Class: JWT::Claims::JwtId

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(validator:) ⇒ JwtId

Initializes a new JwtId instance.

Parameters:

  • validator (#call)

    an object responding to ‘call` to validate the JWT ID.



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.

Parameters:

  • context (Object)

    the context containing the JWT payload.

  • _args (Hash)

    additional arguments (not used).

Returns:

  • (nil)

Raises:



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