Sha256: 4b74c5cc6da558da932210b35df3b006f964d4c905ed64dcc62a673ccd0da605

Contents?: true

Size: 929 Bytes

Versions: 11

Compression:

Stored size: 929 Bytes

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

  belongs_to :owner, polymorphic: true
  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 can?(do_permission)
    do_permission.to_s.in? Array(self.permissions)
  end

  private

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
devise_oauth2_rails4-2.1.8 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.7 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.6 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.5 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.4 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.3 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.0.3 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.1.0 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.0.2 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.0.1 app/models/devise/oauth2/access_token.rb
devise_oauth2_rails4-2.0.0 app/models/devise/oauth2/access_token.rb