Hello everyone,
Using Swashbuckle.AspNetCore v1.0.0, I configured as below:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = ".NET API", Version = "v1" });
c.AddSecurityDefinition("Bearer", new ApiKeyScheme
{
Description = "Example: \"Authorization: Bearer {token}\"",
Name = "Authorization",
In = "header",
Type = "apiKey"
});
});
It worked fine.
After that, I upgrade the latest version Swashbuckle.AspNetCore v2.3.0, no change the code and try to run swagger, but it doesn't work, I check the request header, missing the bearer authentication header.
See the picture:
Please tell me why? How to fix it?
Thanks in advance.
Add this after your code:
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", new string[] { } },
});
Above guidance is correct. Also, this is a dup of #603
Most helpful comment
Add this after your code: