[MonoTouch] Windows Auth and MonoTouch

Paul Bowden pbowden at microsoft.com
Fri Oct 2 00:04:32 EDT 2009


Hmm, that's what I was using before. The app works if Basic auth is enabled on the vdir, but if I disable Basic, which just leaves Windows Auth enabled, I get this:

Unhandled Exception: System.Net.WebException: Invalid length. ---> System.FormatException: Invalid length.
  at (wrapper managed-to-native) System.Convert:InternalFromBase64String (string,bool)
  at System.Convert.FromBase64String (System.String s) [0x00000] 
  at Mono.Http.NtlmSession.Authenticate (System.String challenge, System.Net.WebRequest webRequest, ICredentials credentials) [0x00000] 
  at Mono.Http.NtlmClient.Authenticate (System.String challenge, System.Net.WebRequest webRequest, ICredentials credentials) [0x00000] 
  at System.Net.NtlmClient.Authenticate (System.String challenge, System.Net.WebRequest webRequest, ICredentials credentials) [0x00000] 
  at System.Net.AuthenticationManager.DoAuthenticate (System.String challenge, System.Net.WebRequest request, ICredentials credentials) [0x00000] 
  at System.Net.AuthenticationManager.Authenticate (System.String challenge, System.Net.WebRequest request, ICredentials credentials) [0x00000] 
  at System.Net.HttpWebRequest.CheckAuthorization (System.Net.WebResponse response, HttpStatusCode code) [0x00000] 
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] 
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] 

Here's the relevant part of the source:

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "text/xml; charset=utf-8";
            request.Credentials = new NetworkCredential(userName, password, domain);
________________________________________
From: monotouch-bounces at lists.ximian.com [monotouch-bounces at lists.ximian.com] on behalf of Gonzalo Paniagua Javier [gonzalo.mono at gmail.com]
Sent: Thursday, October 01, 2009 8:40 PM
To: monotouch at lists.ximian.com
Subject: Re: [MonoTouch] Windows Auth and MonoTouch

On Fri, 2009-10-02 at 03:32 +0000, Paul Bowden wrote:
> Oh, cool - I didn't realize that. I tried searching around for an example code snippet, but couldn't find anything. Do you have an example of how to implement this with HttpWebRequest?

You do the same that you do for basic or digest authentication, only
that setting PreAuthenticate to 'true' will not save you a round-trip
(NTLM requires 2 or 3).

        HttpWebRequest req = (HttpWebRequest) WebRequest.Create (YOUR_WINDOWS_SERVER);
        req.Credentials = new NetworkCredentials ("user", "pass"); // This can take a domain too
        ...


-Gonzalo


_______________________________________________
MonoTouch mailing list
MonoTouch at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch



More information about the MonoTouch mailing list