I have ASP.Net Core 2.1
app (API). Need to include the Authorize button in the swagger docs
This app is using Token-Based Authorization with AWS Cognito & here is Swagger Configuration
services.AddSwaggerGen(c =>
{
var security = new Dictionary<string, IEnumerable<string>>
{
{"Bearer", new string[] { }},
};
c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info()
{
Version = "v1.0",
Title = "My API",
Description = "My WebAPIs build on .Net Core 2.1",
Contact = new Swashbuckle.AspNetCore.Swagger.Contact()
{
Name = "Ram",
Email = "myemail@email.com"
}
});
c.AddSecurityDefinition("OAut2", new ApiKeyScheme
{
Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
In = "header",
Name = "Authorization",
Type = "apikey"
});
//c.AddSecurityRequirement(security);
//c.OperationFilter<SecurityRequirementsOperationFilter>();
});
The above configuraiton adds a Authorize button at the top of the document. But when I click the button it display as
But with below link reference.Attached is desired.
Also when I uncomment the below line in configuration,it adds a lock icon on every endpoint while I need to add the lock icon on the endpoints that need authentication.
c.AddSecurityRequirement(security);
How do I get rid of these 2 errors?
Thanks!