【发布时间】:2020-10-22 03:09:01
【问题描述】:
我是 AzureAD 身份验证的新手。我在 startup.cs 中使用以下设置设置了我的 Web API
services.AddAuthentication(sharedopt => sharedopt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer("AzureAd", options =>
{
options.Audience = Configuration.GetValue<string>("AzureAd:Audience");
options.Authority = Configuration.GetValue<string>("AzureAd:Instance")
+ Configuration.GetValue<string>("AzureAd:TenantId");
options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidIssuer = Configuration.GetValue<string>("AzureAd:Issuer"),
ValidAudience = Configuration.GetValue<string>("AzureAd:Audience")
};
});
我希望我的客户端应用程序 (Angular) 将在其请求中附加授权标头,因此它将获得对 API 的访问权限
但是当我执行 Web API 并尝试使用 Authorize 打开任何 API 时,它会触发此错误
InvalidOperationException:未指定 authenticationScheme,并且 没有找到 DefaultChallengeScheme。默认方案可以是 使用 AddAuthentication(string defaultScheme) 或 AddAuthentication(Action configureOptions)。
我已经指定了 JWTBearerDefaults.AuthenticationScheme。还是为什么不接受?
【问题讨论】:
标签: c# asp.net-web-api .net-core jwt azure-active-directory