【发布时间】:2017-12-24 14:09:14
【问题描述】:
我使用 dot net core 1.1 开发了一个 Web 应用程序。在我更新到 asp core 2.0 之前它工作正常。然后在尝试使用该应用程序时,它会报告此错误:
InvalidOperationException:未指定 authenticationScheme,并且 没有找到 DefaultChallengeScheme。
JwtBearerAuthentication 的身份验证配置,在Startup.cs 的Configure 方法中之前如下所示:
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
TokenValidationParameters = tokenValidationParameters
});
在遇到此错误后,我已将其更新为这个:
app.UseJwtBearerAuthentication(new JwtBearerOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
TokenValidationParameters = tokenValidationParameters,
AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme
});
但错误消息仍然存在。我是在寻找错误的地方,还是必须添加其他配置才能使身份验证系统正常工作?
【问题讨论】:
-
身份验证在 2.0 中已更改。更多信息:github.com/aspnet/Announcements/issues/262
-
TL;DR:只需要中间件是
app.UseAuthentication();,并且您将身份验证处理程序定义为ConfigureServices()中的服务。
标签: asp.net-core restful-authentication