Class: HasHelpers::ServiceTrust::ReplayCache

Inherits:
Object
  • Object
show all
Defined in:
lib/has_helpers/service_trust/replay_cache.rb

Class Method Summary collapse

Class Method Details

.claim!(jti, ttl:) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
# File 'lib/has_helpers/service_trust/replay_cache.rb', line 7

def claim!(jti, ttl:)
  raise InvalidTokenError, "missing jti" if jti.blank?

  ttl = ttl.to_i + HasHelpers::ServiceTrust.config.clock_skew.to_i
  ttl = 1 if ttl < 1
  result = redis.set("service_trust:jti:#{jti}", "1", nx: true, ex: ttl)
  raise ReplayDetectedError, "token replay detected" unless result

  true
end