gpt4 book ai didi

swagger - 使用 Swagger-Net 在 Swagger 中发送不记名 token

转载 作者:行者123 更新时间:2023-12-01 12:10:08 28 4
gpt4 key购买 nike

我最近从 Swashbuckle 过渡到 Swagger-Net .进行更改后我遇到的一个问题是,现在我无法调用需要在 Authorization header 中发送 token 的 API。下面是我在 SwaggerConfig.cs 中的代码之前在 Swashbuckle 和现在 Swagger-Net 中的方式

Swashbuckle

//section for .EnableSwagger
c.ApiKey("apiKey")
.Description("API Key Authentication")
.Name("Authorization")
.In("header");

//section for .EnableSwaggerUI
c.EnableApiKeySupport("Authorization", "header");

Swagger-Net
//section for .EnableSwagger
c.ApiKey("Authorization", "header", "API Key Authentication");

对于 Swagger-Net,我在 .EnableSwaggerUI 部分找不到任何等效的 .EnableAPIKeySupport 。在访问/Swagger UI 渲染并使用 Authorize 传递我的 token 后,它不会将该 token 发送到 API。我可以说它没有被发送,因为它不在给定的示例 CURL 中。

最佳答案

是在 Swagger-Net ApiKey是你所需要的全部

c.ApiKey("apiKey", "header", "API Key Authentication", typeof(KeyAuthAttribute));

这是一个工作示例:
http://turoapi.azurewebsites.net/swagger/ui/index#/Echo/Echo_Post

“ protected ”操作将在右侧显示锁定图标
enter image description here

当你执行它们时,你可以看到 curl 有正确的东西
enter image description here

后面的代码在这里:
https://github.com/heldersepu/TuroApi/blob/master/TuroApi/App_Start/SwaggerConfig.cs#L67

关于swagger - 使用 Swagger-Net 在 Swagger 中发送不记名 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52433796/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com