Method: Cosmos::AuthModel.verify

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

.verify(token, permission: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cosmos/models/auth_model.rb', line 32

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

  token_hash = hash(token)
  return true if Store.get(PRIMARY_KEY) == token_hash

  service_hash = Store.get(SERVICE_KEY)
  if ENV['COSMOS_SERVICE_PASSWORD'] and hash(ENV['COSMOS_SERVICE_PASSWORD']) != service_hash
    set_hash = hash(ENV['COSMOS_SERVICE_PASSWORD'])
    Cosmos::Store.set(SERVICE_KEY, set_hash)
    service_hash = set_hash
  end
  return true if service_hash == token_hash and permission != 'admin'

  return false
end