0

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:

enter image description here

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.

Hasan Hasanov
  • 1,129
  • 2
  • 15
  • 23
  • 1
    See the linked question. Cookie auth is not currently supported in Swagger UI and Swagger Editor because of browser restrictions (more details in https://github.com/swagger-api/swagger-js/issues/1163). – Helen Apr 11 '18 at 10:55
  • Thanks @Helen, It is indeed duplicate I will close the question now. – Hasan Hasanov Apr 11 '18 at 11:03

0 Answers0