41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/openc3/models/auth_model.rb', line 41
def self.verify(token, permission: nil)
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
return true if @@service_token_cache and (Time.now - @@service_token_cache_time) < TOKEN_CACHE_TIMEOUT and @@service_token_cache == token_hash and permission != 'admin'
@@token_cache = Store.get(PRIMARY_KEY)
@@token_cache_time = Time.now
return true if @@token_cache == token_hash
@@service_token_cache = Store.get(SERVICE_KEY)
@@service_token_cache_time = @@token_cache_time
if ENV['OPENC3_SERVICE_PASSWORD'] and hash(ENV['OPENC3_SERVICE_PASSWORD']) != @@service_token_cache
set_hash = hash(ENV['OPENC3_SERVICE_PASSWORD'])
OpenC3::Store.set(SERVICE_KEY, set_hash)
@@service_token_cache = set_hash
end
return true if @@service_token_cache == token_hash and permission != 'admin'
return false
end
|