When you create a Consumer, you can specify a key
with keyauth_credentials
(declarative configuration) or the /consumers/{usernameOrId}/key-auth-enc
endpoint.
When authenticating, Consumers must specify their key in either the query, body, or header:
Use
|
Example
|
Description
|
Key in query
|
curl http://localhost:8000/$PROXY_PATH?apikey=$APIKEY
|
To use the key in URL queries, set the configuration parameter
config.key_in_query to
true (default option).
|
Key in body
|
curl http://localhost:8000/$PROXY_PATH \
--data 'apikey: {some_key}'
|
To use the key in a request body, set the configuration parameter
config.key_in_body to true .
The default value is false .
|
Key in header
|
curl http://kong:8000/$PROXY_PATH \
-H 'apikey: $APIKEY'
|
To use the key in a request body, set the configuration parameter
config.key_in_header
to true (default option).
|
Use the following recommendations for each key location:
-
Recommended: Use
config.key_in_header
(enabled by default) as the most common and
secure way to do service-to-service calls.
- If you need to share links to browser clients, use
config.key_in_query
(enabled by default).
Be aware that query parameter requests can appear within application logs and URL browser bars, which expose the API key.
- If you are sending a form with a browser, such as a login form, use
config.key_in_body
.
This option is set to false
by default because it’s a less common use case, and is a more expensive and less performant request.
For better security, only enable the key locations that you need to use.