Note that there are some explanatory texts on larger screens.

plurals
  1. POApache NTLM Auth from C# client do not work with self defined NetworkCredentials
    primarykey
    data
    text
    <p>I have a office plugin that connect a service using <code>HttpWebRequest</code>.</p> <p>Inside a domain I pass <code>CredentialCache.DefaultNetworkCredentials</code> so all is fine. Outside a domain a user need to provide username, domain and password. This don't work atm.</p> <p>Some part of the code out of it:</p> <pre><code>CookieContainer cookies = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = WebRequestMethods.Http.Post; request.AllowAutoRedirect = true; request.CookieContainer = cookies; // provide session cookie to handle redirects of login controller of the webservice if (isWindowAuthentication) // isWindowAuthentication is set earlier by config { if (Common.UserName.Length &gt; 0) { string[] domainuser; string username; string domain; if (Common.UserName.Contains("@")) { domainuser = Common.UserName.Split('@'); username = domainuser[0]; domain = domainuser[1]; } else { domainuser = Common.UserName.Split('\\'); username = domainuser[1]; domain = domainuser[0]; } NetworkCredential nc = new NetworkCredential(username, Common.Password, domain); CredentialCache cache = new CredentialCache(); cache.Add(request.RequestUri, "NTLM", nc); request.Credentials = cache; } else { request.Credentials = CredentialCache.DefaultNetworkCredentials; } } </code></pre> <p>Later on I do the request <code>request.GetResponse();</code>. If I use <code>CredentialCache.DefaultNetworkCredentials</code> then everything works fine. The moment I switch to my own <code>new NetworkCredential()</code> part the authentication fails.</p> <p>I checked the logs of the Apache (it is Apache 2.2 using SSPI mod). When it succeed the first request redirect to the login controller, then the login controller request credentials. Passed and works (redirect to the target site).</p> <p>Log 1 (works):</p> <pre><code>192.168.14.9 - - [25/Oct/2012:11:35:35 +0200] "POST /ror/ioi/start?document%5Bguid%5D=%7Be3d8f1de-10f2-4493-a0c0-97c2acb034e6%7D HTTP/1.1" 302 202 192.168.14.9 - - [25/Oct/2012:11:35:35 +0200] "GET /ror_auth/login?ror_referer=%2Fror%2Fioi%2Fstart%3Fdocument%255Bguid%255D%3D%257Be3d8f1de-10f2-4493-a0c0-97c2acb034e6%257D HTTP/1.1" 401 401 192.168.14.9 - - [25/Oct/2012:11:35:35 +0200] "GET /ror_auth/login?ror_referer=%2Fror%2Fioi%2Fstart%3Fdocument%255Bguid%255D%3D%257Be3d8f1de-10f2-4493-a0c0-97c2acb034e6%257D HTTP/1.1" 401 401 192.168.14.9 - rausch [25/Oct/2012:11:35:35 +0200] "GET /ror_auth/login?ror_referer=%2Fror%2Fioi%2Fstart%3Fdocument%255Bguid%255D%3D%257Be3d8f1de-10f2-4493-a0c0-97c2acb034e6%257D HTTP/1.1" 302 156 </code></pre> <p>The own credential results here Log 2 (do not work):</p> <pre><code>192.168.14.9 - - [25/Oct/2012:12:05:23 +0200] "POST /ror/ioi/start?document%5Bguid%5D=%7B6ac54e8a-19f1-4ccd-9684-8d864dd9ccf7%7D HTTP/1.1" 302 202 192.168.14.9 - - [25/Oct/2012:12:05:23 +0200] "GET /ror_auth/login?ror_referer=%2Fror%2Fioi%2Fstart%3Fdocument%255Bguid%255D%3D%257B6ac54e8a-19f1-4ccd-9684-8d864dd9ccf7%257D HTTP/1.1" 401 401 </code></pre> <p>What I don't understand is when I inspect e.g. <code>CredentialCache.DefaultNetworkCredentials.UserName</code> then is is empty.</p> <p>Anyone know what to do and how I have to set my own credentials correct that the authentication works as expected?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload