Sha256: 5421a035bb9d8b433e20097fc4182c1532f7fd47454c836dc0e0a3cec9067f5e

Contents?: true

Size: 590 Bytes

Versions: 3

Compression:

Stored size: 590 Bytes

Contents

require 'expirable_token'

class Devise::Oauth2Providable::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

3 entries across 3 versions & 1 rubygems

Version Path
devise_oauth2_providable-1.0.1 app/models/devise/oauth2_providable/access_token.rb
devise_oauth2_providable-1.0.0 app/models/devise/oauth2_providable/access_token.rb
devise_oauth2_providable-1.0.0.beta1 app/models/devise/oauth2_providable/access_token.rb