Class: Authify::API::Models::TrustedDelegate

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
Core::SecureHashing
Includes:
JSONAPIUtils, Core::SecureHashing
Defined in:
lib/authify/api/models/trusted_delegate.rb

Overview

Trusted Delegates are remote applications that can do anything

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JSONAPIUtils

#jsonapi_serializer_class_name

Instance Attribute Details

#secret_keyObject

Returns the value of attribute secret_key.



10
11
12
# File 'lib/authify/api/models/trusted_delegate.rb', line 10

def secret_key
  @secret_key
end

Class Method Details

.from_access_key(access, secret) ⇒ Object



32
33
34
35
# File 'lib/authify/api/models/trusted_delegate.rb', line 32

def self.from_access_key(access, secret)
  trusted_delegate = find_by_access_key(access)
  trusted_delegate if trusted_delegate && trusted_delegate.compare_secret(secret)
end

.generate_access_keyObject



28
29
30
# File 'lib/authify/api/models/trusted_delegate.rb', line 28

def self.generate_access_key
  to_hex(SecureRandom.gen_random(48))[0...48]
end

Instance Method Details

#compare_secret(unencrypted_string) ⇒ Object



20
21
22
# File 'lib/authify/api/models/trusted_delegate.rb', line 20

def compare_secret(unencrypted_string)
  compare_salted_sha512(unencrypted_string, secret_key_digest)
end

#set_secret!Object



24
25
26
# File 'lib/authify/api/models/trusted_delegate.rb', line 24

def set_secret!
  self.secret_key = self.class.generate_access_key + self.class.generate_access_key
end