Asp.NetCore3.1 WebApi 使用Jwt 授权认证使用
1:导入NuGet包 Microsoft.AspNetCore.Authentication.JwtBearer 2:配置 jwt相关信息 3:在 startUp中 1 public void ConfigureServices(IServiceCollection services){ 2 #region JWT 认证 3 services 4 .AddAuthentication(JwtBearerDefaults.AuthenticationScheme) 5 .AddJwtBearer(options => { 6 var jsonmodel = AppJsonHelper.InitJsonModel(); 7 options.TokenValidationParameters = new TokenValidationParameters 8 { 9 ValidIssuer = jsonmodel.Issuer, // Configuration["JwtSetting:Issuer"], 10 ValidAudience = jsonmodel.Audience, // Configuration["JwtSetting:Audience"], 11 // IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8