Module: TokenSecretAuth

Defined in:
lib/token_secret_auth/base.rb,
lib/token_secret_auth/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_SALT =

salt for the id ONLY, optional config - even if user doesn’t change this

the only possible leak is the id
'NaCl NaHCO3 NH4ClO3 NaBr MgCl2'
VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

recommended configuration: TokenSecretAuth.configure do |config|

config.id_salt = 'some appropriate saltiness'

end

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
# File 'lib/token_secret_auth/base.rb', line 20

def configure
  yield self
  @id_salt = DEFAULT_SALT if @id_salt.nil?
  set_hash_id_instance(@id_salt)
end

.hash_idObject

TokenSecretAuth.hash_id returns the stored instance of Hashids

used for generating any Token


12
13
14
# File 'lib/token_secret_auth/base.rb', line 12

def hash_id
  @hid
end

.id_salt=(salt) ⇒ Object

set salt for hashing IDs



27
28
29
# File 'lib/token_secret_auth/base.rb', line 27

def id_salt=(salt)
  @id_salt = salt
end

.included(base) ⇒ Object



78
79
80
# File 'lib/token_secret_auth/base.rb', line 78

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#generate_secretObject

the model can call this method to generate a new password for the user it should then encrypt this password for storage in db



90
91
92
# File 'lib/token_secret_auth/base.rb', line 90

def generate_secret
  self.password = self.class.generate_secret
end

#tokenObject

Returns the object’s ID attribute encoded as a token



83
84
85
86
# File 'lib/token_secret_auth/base.rb', line 83

def token
  return nil if !id
  encode(id)
end