Why does Windows authentication work from local to server, and not from server to server?

I have two sites, A and B A uses the API provided by B , and B requires Windows authentication. Both sites live in Domain D

The API is used through HttpClient , and when Site A runs locally, under my domain account (which is in Domain P ), access is granted. In this case, the HttpClient as follows:

 using(var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials: true })) 

When A deployed to a test server, the above leads to a 401 Unauthorized response. The application pool on the test server runs under a service account in domain D

When explicitly using this service account, like this:

 var credential = new NetworkCredential("service-account", "password", "D"); var cache = new CredentialCache { { new Uri(apiServerUri), "NTLM", credential } }; var handler = new HttpClientHandler { Credentials = cache }; using(var client = new HttpClient(handler)) ... 

And again site A running locally, access is still granted. Access is also granted when accessing the API directly through the browser and specifying the credentials of the service account. Logs indicate that this is definitely a service account used to access the API.

Deploying the above on a test server still results in 401 Unauthorized .

Deploying site A on a local IIS instance also successfully uses API B

Running Site B locally, and then accessing it through Site A locally, results in 401 Unauthorized .

Accessing the API through a browser on the test server, where deployed, and specifying the credentials of the service account, also gives A 401 Unauthorized .

I'm not sure where to go from here - did I miss something in the code to make this work? Or could it be an IIS or AD problem?

+6
source share
1 answer

So far I can’t determine exactly why this work works, or if there is a better way to do it (because it is inconvenient), the following allowed A connect to B when both are sitting on the same server.

Site B has an additional host binding setting in IIS to listen on localhost:12345 . Site A configured to connect to this endpoint, not the domain name for Site B Authentication now works correctly.

I would be wondering if anyone can explain why this is so - I do not like the β€œmagic” corrections.

edit It would seem that this kb article is the probable cause of this behavior. In particular:

When you use the fully qualified domain name (FQDN) or your own host to view a local website hosted on a computer that is running Microsoft Internet Information Services (IIS) 5.1 or later, you may receive an error message that resembles the following: HTTP 401.1 - Unauthorized: login failure This problem occurs when the website uses integrated authentication and has a name that maps to the local feedback address

and

Therefore, authentication fails if the FQDN or user header of the host you are using does not match the local computer name.

Changes to the registry are not really an option on these servers, so it seems like working around is what we will use.

+6
source

Source: https://habr.com/ru/post/987009/


All Articles