Class: Doorkeeper::OAuth::PasswordAccessTokenRequest

Inherits:
Object
  • Object
show all
Includes:
Helpers, Validations
Defined in:
lib/doorkeeper/oauth/password_access_token_request.rb

Instance Attribute Summary collapse

Attributes included from Validations

#error

Instance Method Summary collapse

Methods included from Validations

#validate

Constructor Details

#initialize(server, client, resource_owner, parameters = {}) ⇒ PasswordAccessTokenRequest

Returns a new instance of PasswordAccessTokenRequest.



12
13
14
15
16
17
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 12

def initialize(server, client, resource_owner, parameters = {})
  @server          = server
  @resource_owner  = resource_owner
  @client          = client
  @original_scopes = parameters[:scope]
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 10

def client
  @client
end

#resource_ownerObject

Returns the value of attribute resource_owner.



10
11
12
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 10

def resource_owner
  @resource_owner
end

#serverObject

Returns the value of attribute server.



10
11
12
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 10

def server
  @server
end

Instance Method Details

#access_tokenObject



33
34
35
36
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 33

def access_token
  return unless client.present? && resource_owner.present?
  @access_token ||= Doorkeeper::AccessToken.matching_token_for client, resource_owner.id, scopes
end

#authorizeObject



19
20
21
22
23
24
25
26
27
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 19

def authorize
  validate
  @response = if valid?
    find_or_create_access_token
    TokenResponse.new access_token
  else
    ErrorResponse.from_request self
  end
end

#scopesObject



38
39
40
41
42
43
44
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 38

def scopes
  @scopes ||= if @original_scopes.present?
    Doorkeeper::OAuth::Scopes.from_string(@original_scopes)
  else
    server.default_scopes
  end
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/doorkeeper/oauth/password_access_token_request.rb', line 29

def valid?
  self.error.nil?
end