2

We are porting our Windows 8.1 app to UWP and are experiencing an issue with sending default user credentials for single sign-on. It seems that credentials are not being set, despite setting UseDefaultCredentials = true on the handler. This exact code was working in Windows 8.1.

using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true }))
{
    // client._handle.Credentials is null
    // This call fails authentication with a 401 
    // and Fiddler shows no attempt to pass authentication
    var response = await client.GetStringAsync(new Uri(GlobalConfig.Config.BaseUri, "Presenter/SingleSignOn"));
    ...
}

As noted above, in debugging I can see that client._handle.Credentials is null.

I have also tried setting credentials from the System.Net.CredentialCache, but these appear to return empty credentials and they also result in a null client._handle.Credentials.

var handler = new HttpClientHandler() { Credentials = System.Net.CredentialCache.DefaultCredentials };
var handler = new HttpClientHandler() { Credentials = System.Net.CredentialCache.DefaultNetworkCredentials };

I have double-checked our declared Capabilities as per this answer and they look fine. We have declared capabilities:

  • Enterprise Authentication
  • Internet (client)
  • Private Networks (Client & Server)
  • Removable Storage

I have tried using Windows.Web.HttpClient, but it has the same issue--it doesn't find default credentials, so it prompts via a UI. Am I missing something obvious? Or something non-obvious?

TL;DR - I am having trouble passing default user credentials in HttpClient requests.

Edit: I should add that authentication in general is working. If I pass a username/password explicitly, then it works. Obviously, that's not the goal here.

NSouth
  • 5,067
  • 7
  • 48
  • 83
  • 2
    I would start by using a IE manually and try to connect. See what error messages you get. Often the webpage will give a clue to the issue like a certificate is required. You may have to go into your IE options and allow certain url to be allowed or unblock urls. The IE uses the same credentials as the HttpClient. The default credentials are coming from the windows user account which can be fixed manually using an IE browser and changing options. The other thing that is usful is to use a sniffer like wireshark or fiddler and compare the http packets between go and bad PCs. Compare headers – jdweng Jun 06 '17 at 17:47
  • 1
    Thank you! Using IE helped me determine that my Internet Settings were the issue. It turns out that my server was not in my list of intranet sites. – NSouth Jun 06 '17 at 18:24
  • 1
    Actually, adding the server URL to my intranet sites was not required for the Win 8.1 app, so this isn't a full solution. I will continue investigating in hopes of getting it to work otherwise. – NSouth Jun 06 '17 at 18:48
  • Hi @NSouth, did you find ways to make DefaultCredentials work without adding URL to intranet sites? – aveschini May 20 '19 at 09:27

0 Answers0