module TCellAgent::DoorkeeperInstrumentation

Public Instance Methods

authorize_response() click to toggle source
# File lib/tcell_agent/rails/auth/doorkeeper.rb, line 7
def authorize_response
  result = tcell_authorize_response

  TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
    return result unless TCellAgent.configuration.should_intercept_requests?

    login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
    tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]

    return unless tcell_data

    headers = request.env

    if result.is_a?(Doorkeeper::OAuth::TokenResponse)
      user_id = result.token.resource_owner_id
      login_policy.report_login_success(
        user_id,
        headers,
        tcell_data
      )
    elsif result.is_a?(Doorkeeper::OAuth::ErrorResponse)
      user_id = request.POST['client_id']
      password = nil
      user_valid = nil
      login_policy.report_login_failure(
        user_id,
        password,
        headers,
        user_valid,
        tcell_data
      )
    end
  end

  result
end