1 # == Schema Information
3 # Table name: oauth_applications
5 # id :bigint(8) not null, primary key
6 # owner_type :string not null
7 # owner_id :bigint(8) not null
8 # name :string not null
10 # secret :string not null
11 # redirect_uri :text not null
12 # scopes :string default(""), not null
13 # confidential :boolean default(TRUE), not null
14 # created_at :datetime not null
15 # updated_at :datetime not null
19 # index_oauth_applications_on_owner_type_and_owner_id (owner_type,owner_id)
20 # index_oauth_applications_on_uid (uid) UNIQUE
24 # fk_rails_... (owner_id => users.id)
26 class Oauth2Application < Doorkeeper::Application
27 belongs_to :owner, :polymorphic => true
29 validate :allowed_scopes
31 def authorized_scopes_for(user)
32 authorized_tokens.where(:resource_owner_id => user).sum(Doorkeeper::OAuth::Scopes.new, &:scopes)
38 return if owner.administrator?
40 errors.add(:scopes) if scopes.any? { |scope| Oauth::PRIVILEGED_SCOPES.include?(scope) }