Sha256: 6347403ab6009b508e8d839ce9de4e34bb81636ee04cdcfbd344c8c2db8ea913
Contents?: true
Size: 516 Bytes
Versions: 2
Compression:
Stored size: 516 Bytes
Contents
class ApiKey < ActiveRecord::Base belongs_to :token_authenticatable, polymorphic: true before_create :renew def expired? expired_at < Time.now.utc end def renew! renew save! end private def renew generate_access_token set_expiry_date end def set_expiry_date self.expired_at = SimpleTokenAuth.expire_in.since end def generate_access_token begin self.access_token = SecureRandom.hex end while self.class.exists?(access_token: access_token) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
simple_token_auth-0.0.4 | lib/generators/templates/api_key.rb |
simple_token_auth-0.0.3 | lib/generators/templates/api_key.rb |