Consumer
But this level of depth can be insufficient on some occasions.
The fields for defining a Consumer are defined as below.
The process of identifying a Consumer in APISIX is described below:
- The first step is Authentication. This is achieved by Authentication Plugins like and JWT.
- After authenticating, you can obtain the
id
of the Consumer. Thisid
will be the unique identifier of a Consumer. - The configurations like Plugins and Upstream bound to the Consumer are then executed.
Consumers are useful when you have different consumers requesting the same API and you need to execute different Plugin and Upstream configurations based on the consumer. These need to be used in conjunction with the user authentication system.
Refer to the documentation for the authentication Plugin to further understand the concept of a Consumer.
We can use the Plugin to restrict our user “Jack” from accessing the API.
# Add Jack to the blacklist
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
"plugins": {
"key-auth": {},
"blacklist": [
"jack"
]
}
},
"upstream": {
"127.0.0.1:1980": 1
"type": "roundrobin"
},
"uri": "/hello"
}'
# Repeated tests, all return 403; Jack is forbidden to access this API
$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I