Class: Authify::API::Models::APIKey

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

Overview

Additional, revocable user access

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.



11
12
13
# File 'lib/authify/api/models/apikey.rb', line 11

def secret_key
  @secret_key
end

Class Method Details

.generate_access_keyObject



42
43
44
# File 'lib/authify/api/models/apikey.rb', line 42

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

.generate_secret_keyObject



46
47
48
# File 'lib/authify/api/models/apikey.rb', line 46

def self.generate_secret_key
  to_hex(SecureRandom.gen_random(32))[0...32] + to_hex(SecureRandom.gen_random(32))[0...32]
end

Instance Method Details

#compare_secret(unencrypted_string) ⇒ Object



25
26
27
# File 'lib/authify/api/models/apikey.rb', line 25

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

#populate!Object



37
38
39
40
# File 'lib/authify/api/models/apikey.rb', line 37

def populate!
  set_access!
  set_secret!
end

#set_access!Object



29
30
31
# File 'lib/authify/api/models/apikey.rb', line 29

def set_access!
  self.access_key = self.class.generate_access_key
end

#set_secret!Object



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

def set_secret!
  self.secret_key = self.class.generate_secret_key
end