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
-
.configure {|_self| ... } ⇒ Object
recommended configuration: TokenSecretAuth.configure do |config| config.id_salt = ‘some appropriate saltiness’ end.
-
.hash_id ⇒ Object
TokenSecretAuth.hash_id returns the stored instance of Hashids used for generating any Token.
-
.id_salt=(salt) ⇒ Object
set salt for hashing IDs.
- .included(base) ⇒ Object
Instance Method Summary collapse
-
#generate_secret ⇒ Object
the model can call this method to generate a new password for the user it should then encrypt this password for storage in db.
-
#token ⇒ Object
Returns the object’s ID attribute encoded as a token.
Class Method Details
.configure {|_self| ... } ⇒ Object
recommended configuration: TokenSecretAuth.configure do |config|
config.id_salt = 'some appropriate saltiness'
end
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_id ⇒ Object
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_secret ⇒ Object
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 |
#token ⇒ Object
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 |