Skip to content

Instantly share code, notes, and snippets.

@skarllot
Created July 25, 2025 15:02
Show Gist options
  • Save skarllot/1b117c99e39294dc4c14fd09863d0f51 to your computer and use it in GitHub Desktop.
Save skarllot/1b117c99e39294dc4c14fd09863d0f51 to your computer and use it in GitHub Desktop.
OpenAPI 3.0 with Bearer authentication using Swashbuckle
//First we define the security scheme
c.AddSecurityDefinition("Bearer", //Name the security scheme
new OpenApiSecurityScheme{
Description = "JWT Authorization header using the Bearer scheme.",
Type = SecuritySchemeType.Http, //We set the scheme type to http since we're using bearer authentication
Scheme = "bearer" //The name of the HTTP Authorization scheme to be used in the Authorization header. In this case "bearer".
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement{
{
new OpenApiSecurityScheme{
Reference = new OpenApiReference{
Id = "Bearer", //The name of the previously defined security scheme.
Type = ReferenceType.SecurityScheme
}
},new List<string>()
}
});
// RFC 7235: https://www.rfc-editor.org/rfc/rfc7235#section-5.1
// Ref: https://stackoverflow.com/a/57872872/23266117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment