簡體   English   中英

使用ruby net / http庫,我無法使用進入IIS服務器的基本身份驗證來驗證http請求

[英]Using ruby net/http library I cannot authenticate http request with basic auth going to the IIS server

IIS服務器具有與協商和NTLM一起啟用的基本身份驗證。 這是Response標頭:

{"content-type"=>["text/html"], "server"=>["Microsoft-IIS/10.0"], "www-authenticate"=>["Negotiate", "NTLM", "Basic realm=\"my_realm\""], "x-powered-by"=>["ASP.NET"], "date"=>["Thu, 19 Apr 2018 22:14:06 GMT"], "content-length"=>["1293"]}

使用瀏覽器進行NTLM身份驗證后,我可以輸入用戶憑據來對其進行成功身份驗證。 但是通過Ruby的net / http庫提交請求並進行基本身份驗證,對於同一用戶,我得到401未經身份驗證。 下面是我的代碼嘗試提交成功的get請求:

require 'net/http'
def get(username, password)
uri = URI.parse(URI)
req = Net::HTTP::Get.new(uri.path)
req.basic_auth(username, password)
http = Net::HTTP.start(uri.host, uri.port) do |http|
    resp = http.request(req)
    resp
end

從在IIS服務器上啟用基本身份驗證並通過Ruby net / http庫提交http請求,我已經嘗試了所有掛鈎並進行了充分的研究,但似乎無法使用基本auth向服務器進行身份驗證。 查看響應,我確實懷疑服務器可能期望使用NTLM或協商方案,因為它似乎只是忽略了基本身份驗證。 任何幫助將不勝感激!

用戶名中缺少域條目。 我無法使用用戶名“ testuser”為我的用戶進行身份驗證。 因此,在此處添加域名是訣竅。 對於給定的用戶名“ testuser”和域“ FOO”,這是獨家新聞,使用username =“ FOO \\ testuser”進行身份驗證是可行的。

require 'net/http'
def self.get(username, password)
  uri = URI.parse(URI)
  req = Net::HTTP::Get.new(uri.path)
  req.basic_auth(username, password)
  http = Net::HTTP.start(uri.host, uri.port) do |http|
    resp = http.request(req)
    resp
  end
end

因此,使用這些args調用我的get: get("FOO\\\\testuser", "VapTest1")是我所做的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM