Module: TinyAuth::Model
- Defined in:
- lib/tiny_auth/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_reset_token(expires_in: 2.hours) ⇒ Object
Generates a reset token for a resource.
-
#generate_token(expires_in: 24.hours) ⇒ Object
Generates a stateless token for a resource.
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/tiny_auth/model.rb', line 8 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#generate_reset_token(expires_in: 2.hours) ⇒ Object
Generates a reset token for a resource. A hashed version of the token is stored in the database
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tiny_auth/model.rb', line 62 def generate_reset_token(expires_in: 2.hours) token = SecureRandom.base58(24) digest = TinyAuth.hexdigest(token) expiry = expires_in.from_now update_columns( reset_token_digest: digest, reset_token_expires_at: expiry ) token end |
#generate_token(expires_in: 24.hours) ⇒ Object
Generates a stateless token for a resource
55 56 57 |
# File 'lib/tiny_auth/model.rb', line 55 def generate_token(expires_in: 24.hours) to_signed_global_id(expires_in: expires_in, for: :access).to_s end |