Swashbuckle.aspnetcore: Upgrade version 1.0 to 2.0, the bearer authentication doesn't work. Why?

Created on 21 Mar 2018  路  2Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

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:

noheaderauthentication

Please tell me why? How to fix it?
Thanks in advance.

Most helpful comment

Add this after your code:

c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
     { "oauth2", new string[] { } },
});

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings