如何在ASP.NET Core Web API中编程设置AllowWebApiToBeAuthorizedByACL
你要设置的AllowWebApiToBeAuthorizedByACL属于MicrosoftIdentityOptions,其实可以直接在你现有代码的第二个配置委托里添加该属性的设置,不需要额外操作。修改后的代码如下:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApi( a => { a.Audience = AUD; }, b => { b.ClientId = ClientId; b.Instance = Instance; b.TenantId = TenantId; b.AllowWebApiToBeAuthorizedByACL = true; // 添加此行设置目标属性 });
如果后续需要单独调整这个配置,也可以通过Configure方法单独设置:
services.Configure<MicrosoftIdentityOptions>(options => { options.AllowWebApiToBeAuthorizedByACL = true; });
注意确保你的项目已经引用了正确版本的Microsoft.Identity.Web包,该属性属于这个包下的配置类。
内容的提问来源于stack exchange,提问作者maxspan
相关产品推荐
相关产品推荐

