Sha256: 7a94e5a67291a311aa0e719b989d635cdf0fc45258ba5e44ce6d0c299f688686

Contents?: true

Size: 697 Bytes

Versions: 6

Compression:

Stored size: 697 Bytes

Contents

class Devise::Oauth2Providable::AccessToken < ActiveRecord::Base
  expires_according_to :access_token_expires_in

  before_validation :restrict_expires_at, :on => :create, :if => :refresh_token
  belongs_to :refresh_token

  scope :unexpired, -> { where('expires_at > ?', Time.zone.now) }
  scope :user_id, ->(user_id){ where(user_id: user_id) }

  def token_response
    response = {
      :access_token => token,
      :token_type => 'bearer',
      :expires_in => expires_in
    }
    response[:refresh_token] = refresh_token.token if refresh_token
    response
  end

  private

  def restrict_expires_at
    self.expires_at = [self.expires_at, refresh_token.expires_at].compact.min
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
brycesch-devise_oauth2_providable-1.2.4 app/models/devise/oauth2_providable/access_token.rb
brycesch-devise_oauth2_providable-1.2.3 app/models/devise/oauth2_providable/access_token.rb
brycesch-devise_oauth2_providable-1.2.2 app/models/devise/oauth2_providable/access_token.rb
brycesch-devise_oauth2_providable-1.2.1 app/models/devise/oauth2_providable/access_token.rb
brycesch-devise_oauth2_providable-1.2.0 app/models/devise/oauth2_providable/access_token.rb
brycesch-devise_oauth2_providable-1.1.7 app/models/devise/oauth2_providable/access_token.rb