Sha256: d4eb78fd0a5f4aa6c8f24fc44a6fb19c3d688f31cf4a760620120bcca75fc82f

Contents?: true

Size: 881 Bytes

Versions: 7

Compression:

Stored size: 881 Bytes

Contents

module Restforce

  # Authentication middleware used if username and password flow is used
  class Middleware::Authentication::Password < Restforce::Middleware::Authentication

    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

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

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
restforce-0.1.1 lib/restforce/middleware/authentication/password.rb
restforce-0.1.0 lib/restforce/middleware/authentication/password.rb
restforce-0.0.8 lib/restforce/middleware/authentication/password.rb
restforce-0.0.7 lib/restforce/middleware/authentication/password.rb
restforce-0.0.6 lib/restforce/middleware/authentication/password.rb
restforce-0.0.5 lib/restforce/middleware/authentication/password.rb
restforce-0.0.4 lib/restforce/middleware/authentication/password.rb