Manage API Consumer Credentials
A consumer is an application or a developer who consumes the API. The authentication plugin enabled on a route locks down access, requiring consumers to obtain credentials to access the API.
Consumers are typically created after APIs are published while developers come to apply for credentials. In API7 Enterprise Edition, a consumer requires a unique username to be created. As part of the authentication configuration, you would also add one of the authentication plugins from the list above to the consumer's plugin
field.
In this tutorial, you will create a consumer with key authentication, then use the key to access the API with key authentication.
Prerequisite(s)
- Obtain a User Account with Super Admin or API Provider Role.
- Complete Add Service from API Definition.
- Complete Set Up API Authentication.
Create a Consumer
- Select API Consumers, then click Add API Consumer.
- Enter
tom
as the Name, then click Add.
Enable Key Authentication on the Consumer
- On the Plugins table of the consumer, click Add Plugin.
- Choose
key-auth
as the plugin. - Apply the following configuration to the JSON Editor:
{
"key": "secret-key"
}
- Click Add.
Validate
Send a request with a wrong key:
curl -i 43.129.203.103:32140/pet/1 -H "apikey: wrongkey"
HTTP/1.1 401 Unauthorized
Date: Fri, 01 Sep 2023 03:08:00 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/dev
{"message":"Invalid API key in request"}
Send a request with the correct key:
curl -i 43.129.203.103:32140/pet/1 -H "apikey: secret-key"
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 323
Connection: keep-alive
Date: Fri, 01 Sep 2023 03:09:22 GMT
x-srv-trace: v=1;t=ada7cefb43c4848d
x-srv-span: v=1;s=4221c976c3e1b0fe
Access-Control-Allow-Origin: *
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 119
X-RateLimit-Reset: 1693537822
ETag: W/"143-JIrwO+Sx1/7FTTpJ2ljwAfgaRCY"
Vary: Accept-Encoding
Server: APISIX/dev
{
"name": "Dog",
"photoUrls": [
"https://example.com/dog-1.jpg",
"https://example.com/dog-2.jpg"
],
"id": 1,
"category": {
"id": 1,
"name": "pets"
},
"tags": [
{
"id": 1,
"name": "friendly"
},
{
"id": 2,
"name": "smart"
}
],
"status": "available"
}