Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active June 25, 2020 01:02
Show Gist options
  • Select an option

  • Save PradeepLoganathan/5d5572eff6d67af1051b4e0e4face10d to your computer and use it in GitHub Desktop.

Select an option

Save PradeepLoganathan/5d5572eff6d67af1051b4e0e4face10d to your computer and use it in GitHub Desktop.
OAS 3 for .net core 3.1 using swashbuckle 5- Adding a bearer Security definition
services.AddSwaggerGen(options =>
{
var apiinfo = new OpenApiInfo
{
Title = "theta-CandidateAPI",
Version = "v1",
Description = "Candidate API for thetalentbot",
Contact = new OpenApiContact
{ Name = "thetalentbot", Url = new Uri("https://thetalentbot.com/developers/contact") },
License = new OpenApiLicense()
{
Name = "Commercial",
Url = new Uri("https://thetalentbot.com/developers/license")
}
};
OpenApiSecurityScheme securityDefinition = new OpenApiSecurityScheme()
{
Name = "Bearer",
BearerFormat = "JWT",
Scheme = "bearer",
Description = "Specify the authorization token.",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
};
OpenApiSecurityRequirement securityRequirements = new OpenApiSecurityRequirement()
{
{securityScheme, new string[] { }},
};
options.SwaggerDoc("v1", apiinfo);
options.AddSecurityDefinition("jwt_auth", securityDefinition);
// Make sure swagger UI requires a Bearer token to be specified
options.AddSecurityRequirement(securityRequirements);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment