【问题标题】:Does Rest Client support NTLM Auth?Rest Client 是否支持 NTLM 身份验证?
【发布时间】:2010-11-08 23:02:16
【问题描述】:

Rest Client可以做NTLM认证吗?

我在文档中没有看到身份验证类型的任何选项:

require 'rest_client'

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

:auth_type => 'ntlm' 不起作用,我在文档或 IRC 房间也找不到任何内容。

【问题讨论】:

    标签: ruby web-services rest ntlm rest-client


    【解决方案1】:

    NTLM 要求确实缩小了您可以使用的 HTTP 软件的范围,因为它是针对 Microsoft 的。

    您可能想查看“NTLM Authentication for Ruby with Typhoeus and Curl”,然后考虑使用 Typhoeus 而不是 rest-client。

    【讨论】:

    【解决方案2】:

    从技术上讲,您可以使用 before_execution_proc 参数来实现,它允许您访问内部 Net::HTTP 请求对象。如果您使用的是 ruby​​-ntlm gem,它会向 Net::HTTP 请求添加一个 ntlm_auth 方法。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-04
      • 2013-12-24
      • 1970-01-01
      • 2020-07-12
      • 2016-05-01
      • 2020-01-08
      • 2021-01-29
      • 1970-01-01
      相关资源
      最近更新 更多