NET Core 3.0的JWT身份验证和Swagger
我正在使用.Net core 3.0开发一些Web Api,并希望将其与SwashBuckle.Swagger集成。它工作正常,但是当我添加JWT身份验证时,它无法按我预期的那样工作。为此,我添加了以下代码: services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "My Web API", Version = "v1" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); }); 添加AddSecurityDefinition功能后,我可以看到“授权”按钮,当我单击它时,会看到以下表单: 然后输入Bearer …