相关疑难解决方法(0)

迁移到Swashbuckle.AspNetCore版本5

我正在尝试在.NET Core 3 Preview 5 Web API项目中从Swashbuckle的4.0.1版本迁移到5.0.0-rc2。

我已经完成了项目的编译,并且Swagger UI正常运行,但是我无法使Bearer身份验证正常工作,这是由于我没有正确设置新格式的安全性。

这是我在版本4中使用的旧代码:

c.AddSecurityDefinition("Bearer", new ApiKeyScheme
{
    Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
    Name = "Authorization",
    In = "header",
    Type = "apiKey"
});

var security = new Dictionary<string, IEnumerable<string>>
{
    {"Bearer", new string[] { }},
};

c.AddSecurityRequirement(security);
Run Code Online (Sandbox Code Playgroud)

这就是我将其更改为v5的内容:

c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
    Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] …
Run Code Online (Sandbox Code Playgroud)

c# swagger-ui swashbuckle

20
推荐指数
3
解决办法
5035
查看次数

Swashbuckle Swagger UI OpenID Connect 支持

根据https://swagger.io/docs/specification/authentication/openid-connect-discovery/,Swagger UI 现在支持 OpenID Connect。有谁知道或有一个示例项目来解释如何使用 Swashbuckle 或 NSwag 使用 OpenID Connect 配置 Asp.net Core Web API 项目?

swagger-ui openid-connect swashbuckle asp.net-core-webapi

6
推荐指数
1
解决办法
7594
查看次数