Kong Gateway OSS [ARCHIVE]
0.2.x
PermalinkEnabling Plugins
PermalinkIntroduction
Before you start:
- Make sure you've installed Kong - It should only take a minute!
- Make sure you've started Kong.
- Also, make sure you've added your API to Kong.
In this section, you’ll learn how to enable plugins. One of the core principals of Kong is its extensibility through plugins. Plugins allow you to easily add new features to your API or make your API easier to manage.
First, we’ll have you configure and enable the keyauth plugin to add authentication to your API.
Permalink1. Add plugin to your Kong config
Add `keyauth` under the `plugins_available` property in your Kong instance configuration file should it not already exist:
```yaml
plugins_available:
- keyauth
```
Permalink2. Restart Kong
Issue the following command to restart Kong. This allows Kong to load the plugin.
```bash
$ kong restart
```
**Note:** If you have a cluster of Kong instances that share the configuration, you should restart each node in the cluster.
Permalink3. Configure the plugin for your API
Now that Kong has loaded the plugin, we should configure it to be enabled on your API.
Issue the following cURL request with your API `id` you created previously:
```bash
$ curl -i -X POST \
--url http://localhost:8001/plugins_configurations/ \
--data 'name=keyauth' \
--data 'api_id=YOUR_API_ID' \
--data 'value.key_names=apikey'
```
**Note:** `value.key_names` is the authentication header name each request will require.
Permalink4. Verify that the plugin is enabled for your API
Issue the following cURL request to verify that the [keyauth][keyauth] plugin was enabled for your API:
```bash
$ curl -i -X GET \
--url http://localhost:8000/ \
--header 'Host: mockbin.com'
```
Since you did not specify the required `apikey` header the response should be `401 Unauthorized`:
```http
HTTP/1.1 401 Unauthorized
...
{
"message": "Your authentication credentials are invalid"
}
```
PermalinkNext Steps
Now that you’ve enabled the keyauth plugin lets learn how to add consumers to your API so we can continue proxying requests through Kong.
Go to Adding Consumers ›