Skip to content

Instantly share code, notes, and snippets.

@abdusco
Created May 4, 2021 08:40
Show Gist options
  • Save abdusco/f70cf7d015948e99265081fc82e1dc48 to your computer and use it in GitHub Desktop.
Save abdusco/f70cf7d015948e99265081fc82e1dc48 to your computer and use it in GitHub Desktop.
SwashBuckle configuration for bearer tokens
services.AddSwaggerGen(c =>
{
// ...
c.AddSecurityDefinition("bearer", new OpenApiSecurityScheme
{
Description =
"Authenticate with an existing JWT token. **Prefix the token with `Bearer`, i.e. `Bearer eyJ...`**",
In = ParameterLocation.Header,
Name = HeaderNames.Authorization,
BearerFormat = "JWT",
Type = SecuritySchemeType.ApiKey,
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
// ... other security requirements
[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