我正在尝试使用Swashbuckle版本 2.3.0 实现Cookie身份验证。 我按下授权按钮后,我想从这里设置一个SESSIONID cookie值:
我按照Swagger docs的文档编写了以下代码:
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);
});
}
我还尝试在SecurityDefinition之后传递SecurityRequirement,但之后它将SESSIONID添加为请求头而不是Cookie值。
options.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "cookieAuth", new string[] { } }
});
有没有办法实现这一目标?我也在Swashbuckle的github页面上找不到任何东西。