AspNet.Core app using Windows Authentication, client does not negotiate after OPTIONS request

Having an issue with an AspNet.Core app that is using Windows Authentication and CORS. Windows auth works fine for direct API calls. But client fails to initiate negotiate after an OPTIONS request (the API returns 401 with www-authenticate Negotiate, and the client fails).

I’ve simplified the app down to a small sample.

Application Setup:

        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
            builder.Services.AddAuthorization();

            builder.Services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder => builder
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .WithOrigins("https://<my origin>")
                    .WithExposedHeaders("WWW-Authenticate")
                    .AllowCredentials()
                );
            });

            builder.Services.AddControllers();
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();

            builder.WebHost.ConfigureKestrel(options =>
            {
                options.ListenAnyIP(5001, listenOptions =>
                {
                    listenOptions.UseHttps("<my cert>", "<my secret>");
                });
            });
            
            var app = builder.Build();

            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseMiddleware<RequestLoggingMiddleware>();
            app.UseMiddleware<ResponseLoggingMiddleware>();
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseCors("CorsPolicy");
            app.MapControllers();

            app.Run();
        }

Controller:

    [ApiController]
    [Route("[controller]")]
    public class IwaController : ControllerBase
    {
        private readonly ILogger<IwaController> _logger;

        public IwaController(ILogger<IwaController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        [Authorize]
        [Route("[action]")]
        public IActionResult SiteCheck()
        {
            var identity = User?.Identity;
            if (identity == null || !identity.IsAuthenticated)
            {
                _logger.LogWarning("SiteCheck: Unauthorized request: " + identity?.IsAuthenticated.ToString() ?? "Null");
                return Unauthorized();
            }

            _logger.LogInformation("SiteCheck: Authorized request: {name} - {type}", identity?.Name, identity?.AuthenticationType);
            return new JsonResult(new { identity?.Name, identity?.AuthenticationType });
        }
    }

Invoking ‘sitecheck’ directly yields an expected windows auth via negotiate. Doing a redirect from ” has a success OPTIONS request (204), with apparent appropriate headers:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: https://<my origin>
Date: Thu, 27 Jun 2024 00:10:42 GMT
Server: Kestrel

But the subsequent GET, doesn’t do the negotiate, it just fails with 401, even though the negotiate header is present in the response:

Content-Length: 0
Date: Thu, 27 Jun 2024 00:10:42 GMT
Server: Kestrel
Www-Authenticate: Negotiate

I’ve tried a number of different approaches with middleware ordering, custom Authorization handlers, and CORS policy, as well as a bunch time googling, in Chat GPT, and searching stackoverflow to no avail.

Would appreciate any suggestions or ideas anyone could provide.

New contributor

Mike Nicolino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật