Search code examples
c#asp.net-web-api2owinrestsharpntlm

RestSharp and NTLM authentication does not work if accessing API via hostname


I am having a problem with NTLM authentication on Owin selfhosted Web Api. NTLM is enabled on both server and client side. In client I am using RestSharp.

Client

 _client = new RestClient(ConfigurationManager.AppSettings["UserAccessApi"]);
 _client.Timeout = 5000;
 _client.Authenticator = new NtlmAuthenticator();

Service

var listener =
 (System.Net.HttpListener)app.Properties["System.Net.HttpListener"];
listener.AuthenticationSchemes = System.Net.AuthenticationSchemes.IntegratedWindowsAuthentication;

app.UseWebApi(config);

If I access this API via IP or Chrome browser it just works, while if access it through hostname or internet explorer, it does not. I assume this is related to restsharp using httpclient which uses IE engine, which in our company has some local/public networks security settings which are getting in a way for IE. Anybody had similar issue and have any idea how to overcome it without going the "Change IE settings" way?

HostName based call header

enter image description here

IP Based call header

enter image description here

Fiddler log, 1st batch - hostname call, 2nd batch - ip

enter image description here


Solution

  • Using AuthenticationSchemes.Ntlm should help. But it's more like a workaround, as it'll be forcing Ntlm.