I have an aspnetcore API and the host is configured for Windows Auth using the following code.
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseUrls("http://TestServer:5000")
.UseStartup<Startup>()
.UseWebListener(options =>
{
options.Listener.AuthenticationManager.AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes.NTLM;
})
.Build();
host.Run();
The calling client is configured with the following
HttpClientHandler handler = new HttpClientHandler()
{
UseDefaultCredentials = true,
PreAuthenticate = true
};
HttpClient client = new HttpClient(handler);
client.BaseAddress = new Uri("http://TestServer:5000/");
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
In the service I'm calling, I can access the calling user of ClaimsPrincipal Identity.
My question is: how can I call this service from an integration test using the TestServer client initialized using the CreateClient method. What is the best way to ensure that Identity is set when called from an integration test?
I also use XUnit in case you would like to know.
Any help or advice is appreciated.