Ron L
Ron L

Reputation: 11

UWP: Contacting REST API with Windows Integraged Authentication works on developer machine but not on other machines

I am working on a UWP application which will be run on Windows 10 laptops and tablets. The environment it will deployed in requires that all users log into their systems with a smart card (so no username/password). I am using HttpClient to connect to a REST API which is configured for Windows Integrated authentication. When I run on my development machine, either in VS or using the Release Build output I can connect to the API with no issues. However when that Release Build output is installed on a different (non-developer) machine it is unable to connect to the server. The IIS server returns an error with the message: "401 - Unauthorized: Access is denied due to invalid credentials. and the following entry appears in the IIS log:

"2019-07-03 15:49:57 X.X.X.X GET /api/ - 80 - Y.Y.Y.Y - - myserver.com 401 2 5 31"

My IIS server is configured to allow ASP.Net Impersonation and Windows Authentication but no other authentication methods.

The relevant code snippet is:

using (HttpClient client =
    new HttpClient(new HttpClientHandler()
    {
        PreAuthenticate = true,
        UseDefaultCredentials = true,
        Credentials = CredentialCache.DefaultNetworkCredentials
    }))
{
    client.BaseAddress = new Uri(RequestUri);
    client.DefaultRequestHeaders
        .Accept
        .Add(new MediaTypeWithQualityHeaderValue("application/json"));

    HttpResponseMessage response = null;

    try
    {
        response = await client.GetAsync(RequestUri);

    }

....

Can anyone suggest what I am doing incorrectly in my request configuration?

TIA

Ron L

Upvotes: 0

Views: 647

Answers (1)

Ron L
Ron L

Reputation: 11

I found what the problem is. The site being contacted (URL of the API) using Windows Integrated Authentication MUST be added to the list of Intranet Sites in the user's Internet Options. To get to this, open Internet Options from either the Control Panel or the browser, click on the Security tab, click on Local Intranet, Click on the Sites button, click on the Advanced button, and enter the URL into the list.

Upvotes: 1

Related Questions