Sha256: fd069a38ce3065fdc76a7b41fa74f942d483519e5c0f3043064189d92de05a97

Contents?: true

Size: 564 Bytes

Versions: 9

Compression:

Stored size: 564 Bytes

Contents

require 'expirable_token'

class AccessToken < ActiveRecord::Base
  include ExpirableToken
  self.default_lifetime = 15.minutes

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

  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].min
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
devise_oauth2_providable-0.3.8 app/models/access_token.rb
devise_oauth2_providable-0.3.7 app/models/access_token.rb
devise_oauth2_providable-0.3.6 app/models/access_token.rb
devise_oauth2_providable-0.3.5 app/models/access_token.rb
devise_oauth2_providable-0.3.4 app/models/access_token.rb
devise_oauth2_providable-0.3.3 app/models/access_token.rb
devise_oauth2_providable-0.3.2 app/models/access_token.rb
devise_oauth2_providable-0.3.1 app/models/access_token.rb
devise_oauth2_providable-0.3.0 app/models/access_token.rb