class Doorkeeper::Application

def self.authenticate(uid, secret)

def self.authenticate(uid, secret)
  self.where(:uid => uid, :secret => secret).first
end

def self.authorized_for(resource_owner)

def self.authorized_for(resource_owner)
  joins(:authorized_applications)
    .where(oauth_access_tokens: { resource_owner_id: resource_owner.id, revoked_at: nil })
    .group(column_names_with_table.join(','))
end

def self.authorized_for(resource_owner)

def self.authorized_for(resource_owner)
  ids = AccessToken.where(:resource_owner_id => resource_owner.id, :revoked_at => nil).map(&:application_id)
  find(ids)
end

def self.authorized_for(resource_owner)

def self.authorized_for(resource_owner)
  ids = AccessToken.where(:resource_owner_id => resource_owner.id, :revoked_at => nil).map(&:application_id)
  find(ids)
end

def self.authorized_for(resource_owner)

def self.authorized_for(resource_owner)
  ids = AccessToken.where(:resource_owner_id => resource_owner.id, :revoked_at => nil).map(&:application_id)
  find(ids)
end

def self.by_uid(uid)

def self.by_uid(uid)
  self.where(:uid => uid).first
end

def self.column_names_with_table

def self.column_names_with_table
  self.column_names.map { |c| "#{self.table_name}.#{c}" }
end

def self.create_indexes

def self.create_indexes
  ensure_index :uid, :unique => true
end

def self.model_name

def self.model_name
  ActiveModel::Name.new(self, Doorkeeper, 'Application')
end

def generate_secret

def generate_secret
  self.secret ||= UniqueToken.generate
end

def generate_uid

def generate_uid
  self.uid ||= UniqueToken.generate
end

def scopes=(value)

def scopes=(value)
  write_attribute :scopes, value if value.present?
end