In order to give you better service we use cookies. By continuing to use our website, you agree to the use of cookies as described in our Cookie Policy

Kong Logo
  • Request Demo
  • Install
  • Products
    • Kong Gateway
      Install Kong Open Source
      • Overview
      • Control API

        Own your Kong experience to customize your API and microservices workflows.

      • Kong Proxy

        Deliver performance needed for microservices, service mesh, and cloud native deployments.

        • Overview
        • Multi-protocol
      • Kong Plugins

        Unleash the full power of Kong with a robust ecosystem of plugins.

    • Kong Enterprise
      DemoFree Trial
      • Overview
      • Kong Manager

        Monitor and manage all your services with a consumer-grade interface.

        • Overview
      • Teams

        Organize developers and assign permissions to improve efficiency and compliance.

        • Overview
        • RBAC
        • Workspaces
      • Kong Studio

        Empower your developers with the Kong Studio Integrated Development Environment.

      • Dev Portal

        Accelerate innovation across your organization with the Kong Developer Portal.

      • Brain

        Automatically standardize documentation and create a visual map of your services.

      • Immunity

        Autonomously identify service issues with machine learning-powered anomaly detection.

      • Kong for Kubernetes

        The only fully native Kubernetes Ingress Controller for enhanced API management.

      • Enterprise Plugins

        Instantly implement policies built for global scale with Kong Enterprise Plugins.

      • Vitals

        Monitor your Kong Enterprise health and microservice API transactions traversing Kong.

  • Solutions
    • API Gateway

      Take control of your microservices traffic with the world’s most popular API gateway.

    • Kubernetes

      Own your Kubernetes cluster by extending Kong functionality as an ingress controller.

    • Service Mesh

      Inject Kong as a sidecar for your services to go from mess to mesh.

  • Plugins
  • Open Source
    • Install Kong Gateway
    • Kong Community
    • Kubernetes Ingress
    • Kuma
    • Insomnia
  • Docs
    • Get Started
      • Install Kong Gateway
      • Install Kong Enterprise
    • Learn
      • Kong Gateway
      • Kong Enterprise
      • Kong Studio
      • Plugins Hub
  • Resources
    • Learning
      • eBooks
      • Webinars
      • Briefs
      • Blog
      • API Gateway
      • Microservices
    • Community
      • Community
      • Kong Nation
      • Kong Summit
      • GitHub
    • Support
      • Enterprise Support Portal
      • FAQS
  • Company
    • About
    • Customers
    • Investors
    • Careers
    • Partners
    • Press
    • Contact
  • Request Demo
Edit this Page
Kong Kong Enterprise Kong Studio Open Sidebar
Documentation

Enabling Plugins

  • 1.4.x (latest)
  • 1.3.x
  • 1.2.x
  • 1.1.x
  • 1.0.x
  • 0.14.x
  • 0.13.x
  • 0.12.x
  • 0.11.x
  • 0.10.x
  • 0.9.x
  • 0.8.x
  • 0.7.x
  • 0.6.x
  • 0.5.x
  • 0.4.x
  • 0.3.x
  • 0.2.x
Getting Started
  • Introduction
  • Five-minute quickstart
  • Adding your API
  • Enabling Plugins
  • Adding Consumers
Guides & References
  • Configuration reference
  • CLI reference
  • Proxy reference
  • Public Lua API reference
  • Plugin Development Guide
    • Introduction
    • File structure
    • Implement custom logic
    • Plugin configuration
    • Access the datastore
    • Store custom entities
    • Extending the Admin API
    • Writing tests
    • Distribute your plugin
Admin API
  • Supported Content Types
  • Information routes
    • Retrieve node information
    • Retrieve node status
  • API Object routes
    • Add API
    • Retrieve API
    • List APIs
    • Update API
    • Update or create API
    • Delete API
  • Consumer Object routes
    • Create Consumer
    • Retrieve Consumer
    • List Consumers
    • Update Consumer
    • Update or create Consumer
    • Delete Consumer
  • Plugin Object routes
    • Add Plugin
    • Retrieve Plugin
    • List all Plugins
    • List Plugins per API
    • Update Plugin
    • Update or Add Plugin
    • Delete Plugin
    • Retrieve Enabled Plugins
    • Retrieve Plugin Schema
Maybe you were looking for the Enterprise Documentation instead?
Careful! You are browsing documentation for an outdated version of Kong. Go here to browse the documentation for the latest version.

Table of Contents

  • Introduction
  • 1. Add plugin to your Kong config
  • 2. Restart Kong
  • 3. Configure the plugin for your API
  • 4. Verify that the plugin is enabled for your API
  • Next Steps

Introduction

Before you start:
  1. Make sure you've installed Kong - It should only take a minute!
  2. Make sure you've started Kong.
  3. 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 key-auth plugin to add authentication to your API.

1. Add plugin to your Kong config

Add `key-auth` under the `plugins_available` property in your Kong instance [configuration file][configuration] should it not already exist:

```yaml
plugins_available:
  - key-auth
```

2. 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.

3. 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 on the previously created API named `mockbin`:

```bash
$ curl -i -X POST \
  --url http://localhost:8001/apis/mockbin/plugins/ \
  --data 'name=key-auth'
```

**Note:** This plugin also accepts a `config.key_names` parameter, which defaults to `[apikey]`. It is a list of headers and parameters names (both are supported) that are supposed to contain the API key during a request.

4. Verify that the plugin is enabled for your API

Issue the following cURL request to verify that the [key-auth][key-auth] 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 or parameter, the response should be `403 Forbidden`:

```http
HTTP/1.1 403 Forbidden
...

{
  "message": "Your authentication credentials are invalid"
}
```

Next Steps

Now that you’ve enabled the key-auth plugin lets learn how to add consumers to your API so we can continue proxying requests through Kong.

Go to Adding Consumers ›

  • Kong
    Star
  • Products
    • Kong
    • Kong Enterprise
    • Kong Studio
    • Subscriptions
  • Resources
    • Enterprise Support
    • Documentation
    • Partners
    • Webinars
    • Ebooks
  • Company
    • About
    • Customers
    • Investors
    • News
    • Careers Hiring!
    • Kong Summit
    • Contact
  • Open Source
    • Install
    • GitHub
    • Kong Nation
    • Community
  • © Kong Inc. 2019   Terms•Privacy