Class: Restforce::Middleware::Authentication::Password

Inherits:
Restforce::Middleware::Authentication show all
Defined in:
lib/restforce/middleware/authentication/password.rb

Overview

Authentication middleware used if username and password flow is used

Instance Method Summary collapse

Methods inherited from Restforce::Middleware::Authentication

#call, #connection, #error_message, #force_authenticate?

Methods inherited from Restforce::Middleware

#client, #connection, #initialize

Constructor Details

This class inherits a constructor from Restforce::Middleware

Instance Method Details

#authenticate!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/restforce/middleware/authentication/password.rb', line 6

def authenticate!
  response = connection.post '/services/oauth2/token' do |req|
    req.body = URI.encode_www_form(
      :grant_type    => 'password',
      :client_id     => @options[:client_id],
      :client_secret => @options[:client_secret],
      :username      => @options[:username],
      :password      => password
    )
  end
  raise Restforce::AuthenticationError, error_message(response) if response.status != 200
  @options[:instance_url] = response.body['instance_url']
  @options[:oauth_token]  = response.body['access_token']
end

#passwordObject



21
22
23
# File 'lib/restforce/middleware/authentication/password.rb', line 21

def password
  "#{@options[:password]}#{@options[:security_token]}"
end