1

I'm trying to call into a server that serves different realm values for Basic Auth when accessing different sub-urls.

The client code I had so far didn't have to handle this, it just set credentials, set the request.PreAuthenticate = true; and everything worked fine for the communication:

    var request = (HttpWebRequest)WebRequest.Create("http://localhost:8877/" + suburl);
    request.Method = WebRequestMethods.Http.Get;
    request.Credentials = new System.Net.NetworkCredential("User", "Pass");
    request.CookieContainer = cookies;
    request.PreAuthenticate = true;


        using (var response = request.GetResponse())
        {
            UseResponse(response);
        }

This automagically handles the inital 401 response and then transfers the credentials on each subsequent request.

What I do need to do now would be to somehow provide credentials based on the realm value that is returned in the 401 / WWW-Authenticate: header.

Is there any built-in support for this in these classes or in the version using a CredentialsCache? The NetworkCredential class only has user, pass, and domain properties.

The main problem I'm having with PreAuthenticate is that it is unclear what it is caching the credentials for - currently, from what I can see, I assume that it caches the credentials once per root URL (the Uri key of the CredentialCache), so there's no way realm can work with this, but maybe I'm misunderstanding something here ...

Community
  • 1
  • 1
Martin Ba
  • 37,187
  • 33
  • 183
  • 337

0 Answers0