asp.net-web-api - Swagger Bearer Authentication 未显示 [GET] 请求的授权 JWT 令牌字段
问题描述
授权字段显示HTTP POST
请求,但未显示GET
请求添加令牌以进行 Web API 身份验证。
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "Mach.CharterPad.API");
c.OperationFilter<SwaggerAuthorizationFilter>();
c.RootUrl(req => $"{req.RequestUri.GetLeftPart(UriPartial.Authority)}{req.GetConfiguration().VirtualPathRoot.TrimEnd('/')}{appvirtualpath}/api");
}).EnableSwaggerUi();
public class SwaggerAuthorizationFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters != null)
{
operation.parameters.Add(new Parameter
{
name = "Authorization",
@in = "header",
description = "access token",
required = false,
type = "string"
});
}
}
}
解决方案
推荐阅读
- ruby-on-rails - Rails 错误消息显示太多细节
- javascript - Shopify 检索有关特定产品的数据
- c++ - 如何枚举远程计算机上的卷?
- javascript - 开玩笑防止节点模块被导入
- visual-studio-2019 - Visual Studio 2019 发布(或从服务器替换)单个选定文件不可用
- python - 如何通过 Pandas 中的循环加入多个 DataFrame?
- file - 我无法通过 Flywheel 从本地加载 WordPress
- r - 无法在 R Shiny 中使用 renderDT 修复第一列?
- ocaml - 语法错误:caml 中的操作员预期是什么意思?
- javascript - 无法删除或更新父行:外键约束失败 - 续集