class Doorkeeper::OAuth::BaseRequest

Attributes

grant_type[R]
server[R]

Public Instance Methods

after_successful_response() click to toggle source
# File lib/doorkeeper/oauth/base_request.rb, line 49
def after_successful_response
  Doorkeeper.config.after_successful_strategy_response.call(self, @response)
end
authorize() click to toggle source
# 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 == Errors::InvalidRequest
    @response = InvalidRequestResponse.from_request(self)
  else
    @response = ErrorResponse.from_request(self)
  end
end
before_successful_response() click to toggle source
# File lib/doorkeeper/oauth/base_request.rb, line 45
def before_successful_response
  Doorkeeper.config.before_successful_strategy_response.call(self)
end
find_or_create_access_token(client, resource_owner, scopes, custom_attributes, server) click to toggle source
# File lib/doorkeeper/oauth/base_request.rb, line 29
def find_or_create_access_token(client, resource_owner, scopes, custom_attributes, server)
  context = Authorization::Token.build_context(client, grant_type, scopes, resource_owner)
  application = client.is_a?(Doorkeeper.config.application_model) ? client : client&.application

  token_attributes = {
    application: application,
    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),
  }

  @access_token =
    Doorkeeper.config.access_token_model.find_or_create_for(**token_attributes.merge(custom_attributes))
end
scopes() click to toggle source
# File lib/doorkeeper/oauth/base_request.rb, line 25
def scopes
  @scopes ||= build_scopes
end

Private Instance Methods

build_scopes() click to toggle source
# File lib/doorkeeper/oauth/base_request.rb, line 55
def build_scopes
  if @original_scopes.present?
    OAuth::Scopes.from_string(@original_scopes)
  else
    client_scopes = @client&.scopes
    return default_scopes if client_scopes.blank?

    default_scopes & client_scopes
  end
end