ASP.NET 核心应用程序中的 AAD 身份验证 return 不正确 header

AAD authentication in ASP.NET Core app does not return proper header

我的应用程序中有 AAD 身份验证。不幸的是,当未登录的用户请求任何资源时,我得到响应 header:

 WWW-Authenticate: Bearer

但我应该得到回复 header:

WWW-Authenticate: Bearer authorization-uri=https://example.com

有办法实现吗?

您可以更改 JwtBearerOptions.Challenge 属性:

services.AddAuthentication()
    // If use AddJwtBearer
    .AddJwtBearer(opt =>
    {
        opt.Challenge = "Bearer authorization-uri=https://example.com";
    })
    // If use Microsoft.Identity.Web
    .AddMicrosoftIdentityWebApi(configureJwtBearerOptions: opt =>
    {
        opt.Challenge = "Bearer authorization-uri=https://example.com";
    })