NTLM authentication using Windows.Web.Http.HttpClient

核能气质少年 提交于 2019-12-06 07:00:01

问题


I am working on a Windows 10 UWP app that needs to talk to a IIS server using NTLM authentication. I am setting the username and password in the HttpBaseProtocolFilter:

filter.ServerCredential = new PasswordCredential(uri, UserName, Password);

When i view the request in fiddler, it is using Basic Auth. Is there anything I can do to get it to use NTLM, which the server is requiring?


Request Headers:

Content-Length: 1459
Content-Type: text/xml; charset=utf-8
Host: server
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ClientId=XXXXXXXXX
Authorization: Basic XXXXXXXXX

Response Headers:

HTTP/1.1 401 Anonymous Request Disallowed
Server: Microsoft-IIS/8.5
request-id: xxxxx
WWW-Authenticate: NTLM
WWW-Authenticate: Negotiate
X-Powered-By: ASP.NET
X-FEServer: XXXXXXX
Date: Thu, 03 Dec 2015 16:12:58 GMT
Content-Length: 0
Proxy-Support: Session-Based-Authentication

回答1:


Short answer: NTLM auth does work with username / password. Need to retry the connection a second time, because HttpClient is pre-sending BASIC auth when server wants NTLM

Long answer: My app contacts two services hosted on the same server. The first allows Basic auth but the second only allows NTLM. First I connected to the Basic auth service and then I connect to the NTLM one. I would assume the HttpClient would have automatically performed a retry with NTLM when it got the WWW-Authenticate: NTLM header, but it appears that it doesn't. However, if I manually retry the connection, then the second time the HttpClient will perform NTLM auth.



来源:https://stackoverflow.com/questions/34070957/ntlm-authentication-using-windows-web-http-httpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!