3

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.

2 Answers 2

2

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.

3
0

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

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .