我开发了一个使用dot net core 1.1的web应用程序。它工作正常,直到我更新到asp核心2.0。然后尝试使用该应用程序时,它会报告这个错误:JwtBearerAuthentication的ASP Core 2.0 app.UseJwtBearerAuthentication失败
InvalidOperationException: No authenticationScheme was specified, and there was no DefaultChallengeScheme found.
认证的配置,在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中更改。更多信息在这里:https://github.com/aspnet/Announcements/issues/262 – juunas
TL; DR:只有中间件需要的是'app.UseAuthentication();'并且你在'ConfigureServices()'中将认证处理程序定义为服务。 – juunas