我開發了一個使用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