I want to do API key based authentication on a WebAPI project with Swashbuckle (swagger for .net).
I have configured swashbuckle as below:
config
.EnableSwagger(c =>
{
c.ApiKey("apiKey")
.Description("API Key Authentication")
.Name("X-ApiKey")
.In("header");
c.SingleApiVersion("v1", "My API");
})
.EnableSwaggerUi();
(see https://github.com/domaindrivendev/Swashbuckle#describing-securityauthorization-schemes)
It appears to create the swagger file I expect:
"securityDefinitions": { "apiKey": { "type": "apiKey", "description": "API Key Authentication", "name": "X-ApiKey", "in": "header" } }
But when I go to the UI and 'Try it out' it tries to put the API key into the query string (which I think is the default behavior) instead of the headers.
eg:
curl -X POST --header 'Accept: application/json' 'http://localhost:63563/api/MyMethod?api_key=key'
How can I get swagger to use put the API key in the header instead of the query string?
iisreset
command (if you are using full IIS). The configuration sometimes get cached and you won't see the changes. – Hambley