Skip to content

Instantly share code, notes, and snippets.

@kevinah95
Created November 14, 2024 01:08
Show Gist options
  • Save kevinah95/355384c2b351baa517507a5bdd7bac16 to your computer and use it in GitHub Desktop.
Save kevinah95/355384c2b351baa517507a5bdd7bac16 to your computer and use it in GitHub Desktop.
builder.Services.AddSwaggerGen(opt =>
{
opt.SwaggerDoc("v1", new OpenApiInfo { Title = "MyAPI", Version = "v1" });
opt.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "bearer"
});
opt.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment