Module: TinyAuth::Model
- Defined in:
- lib/tiny_auth/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_token(purpose: :access, expires_in: 24.hours) ⇒ String
Generates a token for this resource.
-
#invalidate_tokens ⇒ Object
Invalidate all tokens for this resource.
-
#invalidate_tokens! ⇒ self
Invalidate all tokens for this resource.
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 |
# File 'lib/tiny_auth/model.rb', line 6 def self.included(base) base.extend ClassMethods base.has_secure_password base.before_save :invalidate_tokens, if: :password_digest_changed? end |
Instance Method Details
#generate_token(purpose: :access, expires_in: 24.hours) ⇒ String
Generates a token for this resource.
45 46 47 48 49 50 51 |
# File 'lib/tiny_auth/model.rb', line 45 def generate_token(purpose: :access, expires_in: 24.hours) TinyAuth.verifier.generate( [id, token_version], purpose: purpose, expires_in: expires_in ) end |
#invalidate_tokens ⇒ Object
Invalidate all tokens for this resource. The token version will be incremented, but it will not be written to the database.
62 63 64 |
# File 'lib/tiny_auth/model.rb', line 62 def invalidate_tokens increment(:token_version) end |
#invalidate_tokens! ⇒ self
Invalidate all tokens for this resource. The token version will be incremented and written to the database.
56 57 58 |
# File 'lib/tiny_auth/model.rb', line 56 def invalidate_tokens! increment!(:token_version) end |