module TinyAuth::Model

Public Class Methods

included(base) click to toggle source
# 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

Public Instance Methods

generate_token(purpose: :access, expires_in: 24.hours) click to toggle source

Generates a token for this resource. @param expires_in [ActiveSupport::Duration] defaults to 24 hours @param purpose [Symbol] defaults to `:access` @return [String]

# 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() click to toggle source

Invalidate all tokens for this resource. The token version will be incremented, but it will not be written to the database.

# File lib/tiny_auth/model.rb, line 62
def invalidate_tokens
  increment(:token_version)
end
invalidate_tokens!() click to toggle source

Invalidate all tokens for this resource. The token version will be incremented and written to the database. @return [self]

# File lib/tiny_auth/model.rb, line 56
def invalidate_tokens!
  increment!(:token_version)
end