Created
July 25, 2025 15:02
-
-
Save skarllot/1b117c99e39294dc4c14fd09863d0f51 to your computer and use it in GitHub Desktop.
OpenAPI 3.0 with Bearer authentication using Swashbuckle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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