My question is similar to Postman Windows Authentication (NTLM) not working but there are no answers to it so far.
I have used a .NetCore rest api (netcoreapp3.1).
In launchsettings.json
{ "iisSettings": { "windowsAuthentication": true, "anonymousAuthentication": false, .. }
Startup.cs
public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(IISDefaults.AuthenticationScheme); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //... app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); //....useEndpoints middleware is being called afterwards }
EmployeeController.cs
[Route("IISDetails")] [HttpGet] public IActionResult IISDetails() { var name = User.Identity.Name; return new ContentResult() { Content = $@"IIS authorized. AD: {name}" }; }
I have not used [Authorize] tag so that atleast i can see if this works but Name is always null.
Postman I am setting username in Authorization tab. Image attached for reference.
If I put Authorize attribute to my IISDetails function it gives me
System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.