I'm having some difficulty authenticating a request from a .Net MVC web app to a .Net Core service layer.
The two applications are running on the same IIS server under the same web site. The web application is configured for Windows authentication, but the intention is for it to authenticate to the service layer using the App Pool identity, or another arbitrary AD account. I do not want to pass basic auth credentials with each request to the service layer, nor to I want authenticated users to be able to access service layer controllers directly.
No matter what I do, the web app always seems to be want to call the service layer as an anonymous user. The question is how do I make the request as an authenticated windows user?
I am using HttpClient. It also might be significant that I'm only using HttpClient's async methods - as I've read that async spawns a new thread under a different security context.
Code from the web app is below.
public class SvcClient
{
public SvcClient()
{
string path = System.Configuration.ConfigurationManager.AppSettings["SvcPath"];
Path = path;
}
private string Path { get; set; }
public HttpClient client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = true, UseDefaultCredentials = true });
public async Task<List<Stuff>> GetStuffAsync()
{
string route = "Stuff/List";
List<Stuff> stuff = null;
HttpResponseMessage response = await client.GetAsync(Path + route);
if (response.IsSuccessStatusCode)
{
stuff = await response.Content.ReadAsAsync<List<Stuff>>();
}
return stuff;
}
}