Skip to content

Commit

Permalink
Add scopes to PasswordAccessTokenRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeiniesta committed Mar 14, 2012
1 parent ba23be2 commit 0693d3f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/doorkeeper/oauth/password_access_token_request.rb
Expand Up @@ -15,20 +15,23 @@ class PasswordAccessTokenRequest
:client_secret,
:grant_type,
:username,
:password
:password,
:scope
]

validate :attributes, :error => :invalid_request
validate :grant_type, :error => :unsupported_grant_type
validate :client, :error => :invalid_client
validate :resource_owner, :error => :invalid_resource_owner
validate :scope, :error => :invalid_scope

attr_accessor *ATTRIBUTES
attr_accessor :resource_owner

def initialize(owner, attributes = {})
ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", attributes[attr]) }
@resource_owner = owner
@scope ||= Doorkeeper.configuration.default_scope_string
validate
end

Expand Down Expand Up @@ -91,12 +94,17 @@ def client

def create_access_token
@access_token = Doorkeeper::AccessToken.create!({
:application_id => client.id,
:resource_owner_id => resource_owner.id,
:expires_in => configuration.access_token_expires_in
:application_id => client.id,
:resource_owner_id => resource_owner.id,
:scopes => @scope,
:expires_in => configuration.access_token_expires_in
})
end

def has_scope?
Doorkeeper.configuration.scopes.all.present?
end

def validate_attributes
grant_type.present?
end
Expand All @@ -105,6 +113,11 @@ def validate_client
!!client
end

def validate_scope
return true unless has_scope?
ScopeChecker.valid?(scope, configuration.scopes)
end

def validate_grant_type
grant_type == 'password'
end
Expand Down

0 comments on commit 0693d3f

Please sign in to comment.