I am trying to implement cookie authentication using Swashbuckle version 2.3.0. I want to set a SESSIONID cookie value from here after I press the Authorize button:
I followed the documentation from Swagger docs and wrote the following code:
public static void ConfigureSwagger(IServiceCollection services)
{
services.AddSwaggerGen(options =>
{
var info = new Info()
{
Title = "Title",
Description = "Description",
License = new License { Name = "Sample Name", Url = "http://www.example.com/" }
};
options.SwaggerDoc("sd", info);
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var xmlPath = Path.Combine(basePath, "SD.xml");
options.IncludeXmlComments(xmlPath);
var apiScheme = new ApiKeyScheme()
{
In = "cookie",
Description = "Please insert authentication cookie with session id. Ex: '08e631a283094e8cafb05f0145a8be8b'",
Name = "SESSIONID",
Type = "apiKey"
};
options.AddSecurityDefinition("cookieAuth", apiScheme);
});
}
I have also tried to pass a SecurityRequirement after SecurityDefinition but then it adds the SESSIONID as request header instead of Cookie value.
options.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "cookieAuth", new string[] { } }
});
Is there a way to accomplish that? I also cannot find anything on Swashbuckle's github page.