class OmniAuth::Strategies::HubSpot

Public Instance Methods

callback_phase() click to toggle source
# File lib/omniauth/strategies/hubspot.rb, line 19
def callback_phase
  if request.params['error'] || request.params['error_reason']
    raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
  end
  if !options.provider_ignores_state && (request.params['state'].to_s.empty? || request.params['state'] != session.delete('omniauth.state'))
    raise CallbackError.new(nil, :csrf_detected)
  end

  hash = Hashie::Mash.new
  hash.token = request.params['access_token']
  hash.refresh_token = request.params['refresh_token']
  hash.expires_in = request.params['expires_in']
  self.access_token = hash

  self.env['omniauth.auth'] = auth_hash
  call_app!
rescue ::OAuth2::Error, CallbackError => e
  fail!(:invalid_credentials, e)
rescue ::MultiJson::DecodeError => e
  fail!(:invalid_response, e)
rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
  fail!(:timeout, e)
rescue ::SocketError, Faraday::Error::ConnectionFailed => e
  fail!(:failed_to_connect, e)
end