nictrix
nictrix

Reputation: 1483

Does Rest Client support NTLM Auth?

Can Rest Client do NTLM authentication?

I didn't see any options in the documentation for authentication types:

require 'rest_client'

resource = RestClient::Resource.new 'http://website', :auth_type => 'ntlm', :user => 'USERNAME', :password => 'PASSWORD'
results = resource.get

:auth_type => 'ntlm' doesn't work, and I couldn't find anything on the documentation or IRC room either.

Upvotes: 3

Views: 4671

Answers (2)

Lucas Ridge
Lucas Ridge

Reputation: 1

Technically speaking, you can make it do so using the before_execution_proc arg which lets you access the internal Net::HTTP request objects. If you're using the ruby-ntlm gem it adds a ntlm_auth method to Net::HTTP requests.

require 'ntlm/http'
require 'rest-client'
require 'json'

# Quick monkey patch to rest client payloads since for some reason Net/NTLM insists on playing payload streams backwards.
class RestClient::Payload::Base
  def rewind
    @stream.rewind
  end
end

auth_proc = ->(req, _args){ req.ntlm_auth(username, domain, password)}
res = RestClient::Request.new(method: :post, url: url, payload: payload}, before_execution_proc: auth_proc ).execute
res

Upvotes: 0

the Tin Man
the Tin Man

Reputation: 160551

The NTLM requirement really narrows down what HTTP software you can use due to it being so specific to Microsoft.

You might want to look at "NTLM Authentication for Ruby with Typhoeus and Curl", then look into using Typhoeus instead of rest-client.

Upvotes: 2

Related Questions