Class: JWT::Claims::JwtId

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

Instance Method Summary collapse

Constructor Details

#initialize(validator:) ⇒ JwtId

Returns a new instance of JwtId.



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

def initialize(validator:)
  @validator = validator
end

Instance Method Details

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



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

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