Class: Doorkeeper::OAuth::BaseRequest

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

Instance Attribute Summary collapse

Attributes included from Validations

#error

Instance Method Summary collapse

Methods included from Validations

#valid?, #validate

Instance Attribute Details

#grant_typeObject (readonly)

Returns the value of attribute grant_type


8
9
10
# File 'lib/doorkeeper/oauth/base_request.rb', line 8

def grant_type
  @grant_type
end

#serverObject (readonly)

Returns the value of attribute server


8
9
10
# File 'lib/doorkeeper/oauth/base_request.rb', line 8

def server
  @server
end

Instance Method Details

#after_successful_responseObject


44
45
46
# File 'lib/doorkeeper/oauth/base_request.rb', line 44

def after_successful_response
  server_config.after_successful_strategy_response.call(self, @response)
end

#authorizeObject


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/doorkeeper/oauth/base_request.rb', line 12

def authorize
  if valid?
    before_successful_response
    @response = TokenResponse.new(access_token)
    after_successful_response
    @response
  elsif error == :invalid_request
    @response = InvalidRequestResponse.from_request(self)
  else
    @response = ErrorResponse.from_request(self)
  end
end

#before_successful_responseObject


40
41
42
# File 'lib/doorkeeper/oauth/base_request.rb', line 40

def before_successful_response
  server_config.before_successful_strategy_response.call(self)
end

#find_or_create_access_token(client, resource_owner, scopes, server) ⇒ Object


29
30
31
32
33
34
35
36
37
38
# File 'lib/doorkeeper/oauth/base_request.rb', line 29

def find_or_create_access_token(client, resource_owner, scopes, server)
  context = Authorization::Token.build_context(client, grant_type, scopes, resource_owner)
  @access_token = server_config.access_token_model.find_or_create_for(
    application: client,
    resource_owner: resource_owner,
    scopes: scopes,
    expires_in: Authorization::Token.access_token_expires_in(server, context),
    use_refresh_token: Authorization::Token.refresh_token_enabled?(server, context),
  )
end

#scopesObject


25
26
27
# File 'lib/doorkeeper/oauth/base_request.rb', line 25

def scopes
  @scopes ||= build_scopes
end

#server_configObject


48
49
50
# File 'lib/doorkeeper/oauth/base_request.rb', line 48

def server_config
  Doorkeeper.config
end