Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Basic authorization header in the Swagger in ASP .Net core

How to add basic authorization header in Swagger in Asp .Net core. By default the api key treats as a query string but I need to customize that so that it will include in the header.

like image 334
Rahul Sen Avatar asked Dec 14 '22 02:12

Rahul Sen


1 Answers

If you are using Swashbuckle.AspNetCore v5.0.0-rc2 see below:

   c.AddSecurityDefinition("Basic", new OpenApiSecurityScheme
            {
                Description = "Basic auth added to authorization header",
                Name = "Authorization",
                In = ParameterLocation.Header,
                Scheme = "basic",
                Type = SecuritySchemeType.Http
            });

            c.AddSecurityRequirement(new OpenApiSecurityRequirement
            {
                {
                    new OpenApiSecurityScheme
                    {
                        Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Basic" }
                    },
                    new List<string>()
                }
            });
like image 153
ToDevAndBeyond Avatar answered Dec 17 '22 00:12

ToDevAndBeyond