Skip to main content

Version: 3.2.14.1

Manage Consumer Credentials

A consumer is an application or a developer that consumes your API. Enabling authentication on a route in your API allows you to control access, requiring consumers to obtain the credentials before accessing the route.

Consumers are typically created after APIs are published. In API7 Gateway, creating a consumer requires a unique username and configuring an authentication plugin.

This tutorial guides you in creating a consumer and configuring key authentication.

Prerequisites

  1. Install API7 Enterprise.
  2. Have a running API on the gateway group.

Add a Consumer

  1. Select Consumers of your gateway group from the side navigation bar.
  2. Click Add Consumer.
  3. From the dialog box, do the following:
  • In the Name field, enter Alice.
  • Click Add.
  1. In the consumer you just created under the Plugins field, search for the key-auth plugin.
  2. Click the Plus icon (+).
  3. In the dialog box do the following:
  • Add the following configuration to the JSON Editor:

    {
    "key": "secret-key"
    }
  • Click Enable.

Enable Key Authentication for the Consumer

  1. Select Consumers of your gateway group from the side navigation bar.
  2. Select your consumer, for example, Alice.
  3. In the Plugins field, search for the key-auth plugin.
  4. Click the Plus icon (+).
  5. In the dialog box, do the following:
  • Add the following configuration to the JSON Editor:
    {
    "key": "secret-key"
    }
  • Click Enable.

Validate

Follow the steps below to validate the key authentication.

Send a Request without a Key

Send a request without the apikey header:

curl -i "http://127.0.0.1:9080/ip"  

Since the key is not provided, you will receive an HTTP/1.1 401 Unauthorized response with the following request body:

{"message":"Missing API key found in request"}

Send a Request with a Wrong Key

Send a request with a wrong key in the apikey header:

curl -i "http://127.0.0.1:9080/ip" -H "apikey: wrongkey" 

Since the key is wrong, you will receive an HTTP/1.1 401 Unauthorized response with the following request body:

{"message":"Invalid API key in request"}

Send a Request with the Correct Key

Send a request with the correct key in the apikey header:

curl -i "http://127.0.0.1:9080/ip" -H "apikey: secret-key" 

With the correct key in the request, you will receive an HTTP/1.1 200 OK response with the following request body:

{
"origin": "192.168.0.102, 35.259.159.12"
}

Additional Resource(s)


API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IRed Herring

Copyright © APISEVEN Ltd. 2019 – 2024. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation