Sha256: 696a988745fc205975e43a4d7c83d6f897b1c4fe27c23aa9f2152151ea01bc3e

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

class Devise::Oauth2::AccessToken < ActiveRecord::Base

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

  serialize :permissions

  def permissions=(permissions)
    super(permissions) if permissions.is_a? Array
    permissions = permissions.split(/[,\s\n\b\t]/).keep_if { |x| !x.empty? } if permissions.is_a? String
    super(permissions)
  end

  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

  def method_missing(method)
    if method.to_s.match /^can_.*\?$/
      permission = method.to_s.match(/^can_(.*)\?$/)[1]
      return true if permission.in? self.permissions
      return false
    end
    super(method)
  end

  private

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
devise_oauth2_rails4-1.1.6 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-1.1.5 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-1.1.4 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-1.1.3 app/models/devise/oauth2/access_token.rb