Skip to content

Commit c875f34

Browse files
author
daveywyliedev
committed
Added authorization to swagger
1 parent 4441124 commit c875f34

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

DbLocalizer/Startup.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ public void ConfigureServices(IServiceCollection services)
8484
Email = "DbLocalizer@gmail.com"
8585
}
8686
});
87+
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
88+
{
89+
Name = "Authorization",
90+
Type = SecuritySchemeType.ApiKey,
91+
Scheme = "Bearer",
92+
BearerFormat = "JWT",
93+
In = ParameterLocation.Header,
94+
Description = "Enter 'Bearer' followed by your token in the text input below.\nExample: Bearer <your_token>"
95+
});
96+
97+
options.AddSecurityRequirement(new OpenApiSecurityRequirement
98+
{
99+
{
100+
new OpenApiSecurityScheme
101+
{
102+
Reference = new OpenApiReference
103+
{
104+
Type = ReferenceType.SecurityScheme,
105+
Id = "Bearer"
106+
}
107+
},
108+
new string[] {}
109+
}
110+
});
87111

88112
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
89113
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));

0 commit comments

Comments
 (0)