Method: OpenC3::AuthModel.verify

Defined in:
lib/openc3/models/auth_model.rb

.verify(token) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/openc3/models/auth_model.rb', line 38

def self.verify(token)
  return false if token.nil? or token.empty?

  token_hash = hash(token)
  return true if @@token_cache and (Time.now - @@token_cache_time) < TOKEN_CACHE_TIMEOUT and @@token_cache == token_hash

  @@token_cache = Store.get(PRIMARY_KEY)
  @@token_cache_time = Time.now
  return true if @@token_cache == token_hash

  # Handle a service password - Generally only used by ScriptRunner
  service_password = ENV['OPENC3_SERVICE_PASSWORD']
  return true if service_password and service_password == token

  return false
end