1 引用NuGet包:Microsoft.AspNetCore.Authentication.JwtBearer 2 在Startup中使用以下代码: public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(jwtBearerOptions => { jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true,//是否验证Issuer ValidateAudience = true,//是否验证Audience ValidateLifetime = true,//是否验证失效时间 ValidateIssuerSigningKey = true,//是否验证SecurityKey ValidAudience = "这里自定义", ValidIssuer = "这里自定义", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtSecurityKey"])),//秘钥,长度一定要够长 }; }); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseAuthentication();//配置授权 } 3 在相应的Controller上 增加 Microsoft.AspNetCore.Authorization.AuthorizeAttribute 即可