我想用Swashbuckle(为.net开口)在WebAPI项目上进行基于API密钥的身份验证。swashbuckle头部的API密钥
我已经配置swashbuckle如下:
config
.EnableSwagger(c =>
{
c.ApiKey("apiKey")
.Description("API Key Authentication")
.Name("X-ApiKey")
.In("header");
c.SingleApiVersion("v1", "My API");
})
.EnableSwaggerUi();
(见https://github.com/domaindrivendev/Swashbuckle#describing-securityauthorization-schemes)
这似乎创造招摇文件我想到:
"securityDefinitions": { "apiKey": { "type": "apiKey", "description": "API Key Authentication", "name": "X-ApiKey", "in": "header" } }
但是,当我去到UI和'试一试'它试图将API密钥放入查询字符串(我认为是默认行为)而不是头部。
如:
curl -X POST --header 'Accept: application/json' 'http://localhost:63563/api/MyMethod?api_key=key'
怎样才能昂首阔步使用把API密钥的头而不是查询字符串?
看起来更好的生病下周尝试它的欢呼。 –
它只是工作,它的好得多 –
这对我有用。调整swagger配置设置时,请确保运行'iisreset'命令(如果使用的是完整的IIS)。配置有时会被缓存,并且您不会看到更改。 –