0

I have the following swagger config in .net core3

services.AddSwaggerGen(c =>
{
   c.SwaggerDoc("v1", new OpenApiInfo { 
      Title = "My API", 
      Version = "v1" 
   });

  c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
     In = ParameterLocation.Header, 
     Description = "Please insert JWT with Bearer into field",
     Name = "Authorization",
          Type = SecuritySchemeType.ApiKey 
     });

     c.AddSecurityRequirement(new OpenApiSecurityRequirement {
     { 
        new OpenApiSecurityScheme 
        { 
            Reference = new OpenApiReference 
            { 
              Type = ReferenceType.SecurityScheme,
              Id = "Bearer" 
            } 
        },
        new string[] { } 
      } 
     })
 });

The problem is that the Authorization header is sent, but without the word Bearer in the begining:
Actual:

Authorization: eyJhbGciOiJIUzI...

Expected:

Authorization: Bearer eyJhbGciOiJIUzI...

SexyMF
  • 10,657
  • 33
  • 102
  • 206
  • How're you sending the Authorization Token over by chance? Are you using Angular? Append "Bearer " + token HttpOptions instead of sending just the token & see if it'll work? – dnunez32 Nov 10 '19 at 07:25
  • 1
    Swagger UI, this is a swagger ui problem – SexyMF Nov 10 '19 at 07:26
  • Let me know if this helps: 1) https://stackoverflow.com/questions/58197244/swaggerui-with-netcore-3-0-bearer-token-authorization – dnunez32 Nov 10 '19 at 07:34
  • @dnunez32 - I already tried that: "Unknown security definition type" – SexyMF Nov 10 '19 at 07:39

0 Answers0