Sha256: 3d4233363bf3125f3d712852640a081d1bd155ca9b122bc947e24ed78dcd903e
Contents?: true
Size: 747 Bytes
Versions: 12
Compression:
Stored size: 747 Bytes
Contents
class Oauth2Token < ActiveRecord::Base cattr_accessor :default_lifetime self.default_lifetime = 1.minute belongs_to :user belongs_to :client, class_name: "Site::Client", foreign_key: :site_id validates :client, :expires_at, presence: true validates :token, presence: true, uniqueness: true before_validation :setup, on: :create scope :valid, lambda { where('expires_at >= ?', Time.now.utc) } def expires_in (expires_at - Time.now.utc).to_i end def expire! update_attribute(:expires_at, Time.now.utc) || raise(ActiveRecord::RecordInvalid) end protected def setup self.token = SecureRandom.urlsafe_base64(64) self.expires_at ||= default_lifetime.from_now end end
Version data entries
12 entries across 12 versions & 2 rubygems