she*_*ira 31 c# .net-core asp.net-core asp.net-core-2.0 .net-core-3.0
我有以下代码可以在 .NET Core 2.2 中编译和运行:
byte[] key = Encoding.ASCII.GetBytes(Constants.JWT_SECRET);
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
});
Run Code Online (Sandbox Code Playgroud)
在 .NET Core 3.0 中,我收到错误消息:
错误 CS1061“AuthenticationBuilder”不包含“AddJwtBearer”的定义,并且找不到接受“AuthenticationBuilder”类型的第一个参数的可访问扩展方法“AddJwtBearer”(您是否缺少 using 指令或程序集引用?)
并尝试升级到 3.0 版,这似乎是定义 this 的最后一个版本。如何将 AddJwtBearer 迁移到 Core 3.0?
Mer*_*yın 15
您必须将Microsoft.AspNetCore.Authentication.JwtBearer包包含到您的项目中。Core 3.0 及以上版本为 3.0.0。
| 归档时间: |
|
| 查看次数: |
22512 次 |
| 最近记录: |