Method: Restforce::Middleware::Authentication#authenticate!

Defined in:
lib/restforce/middleware/authentication.rb

#authenticate!Object

Internal: Performs the authentication and returns the response body.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/restforce/middleware/authentication.rb', line 24

def authenticate!
  response = connection.post '/services/oauth2/token' do |req|
    req.body = encode_www_form(params)
  end

  if response.status >= 500
    raise Restforce::ServerError, error_message(response)
  elsif response.status != 200
    raise Restforce::AuthenticationError, error_message(response)
  end

  @options[:instance_url] = response.body['instance_url']
  @options[:oauth_token]  = response.body['access_token']

  @options[:authentication_callback]&.call(response.body)

  response.body
end