Class: Auth::ClientCredentials::AccessTokenTracker

Inherits:
Common::RedisStore show all
Defined in:
lib/lighthouse/auth/client_credentials/access_token_tracker.rb

Constant Summary collapse

TOLERANCE =
5

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Class Method Summary collapse

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

This class inherits a constructor from Common::RedisStore

Class Method Details

.get_access_token(service_name) ⇒ Object



28
29
30
31
# File 'lib/lighthouse/auth/client_credentials/access_token_tracker.rb', line 28

def self.get_access_token(service_name)
  service = find(service_name)
  service&.access_token
end

.set_access_token(service_name, access_token, ttl = redis_namespace_ttl) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/lighthouse/auth/client_credentials/access_token_tracker.rb', line 17

def self.set_access_token(service_name, access_token, ttl = redis_namespace_ttl)
  service = new(service_name:)
  service.access_token = access_token
  service.save!

  # We want to set the TTL dynamically
  # Using TOLERANCE here so that we can avoid using the access_token right as
  # it is expiring
  service.expire(ttl - TOLERANCE)
end