跳转到内容

Consumers & Credentials

此内容尚不支持你的语言。

Consumers represent API clients. Credentials provide authentication for consumers.

interface Consumer {
id: string;
username?: string; // Unique username
customId?: string; // External identifier
tags?: string[];
}
interface Credential {
id: string;
consumerId: string;
credentialType: string; // "api_key", "jwt", etc.
credential: object; // Credential data
tags?: string[];
}
Terminal window
curl http://localhost:8080/api/consumers
Terminal window
curl http://localhost:8080/api/consumers?username=api-client
Terminal window
curl -X PATCH http://localhost:8080/api/consumers/consumer_abc123 \
-H "Content-Type: application/json" \
-d '{
"tags": ["premium", "production"]
}'
Terminal window
curl -X DELETE http://localhost:8080/api/consumers/consumer_abc123
Terminal window
curl http://localhost:8080/api/credentials
Terminal window
curl http://localhost:8080/api/credentials?consumerId=consumer_abc123
Terminal window
curl -X DELETE http://localhost:8080/api/credentials/credential_xyz789

Bind key-auth plugin to a route or service:

Terminal window
curl -X POST http://localhost:8080/api/plugins \
-H "Content-Type: application/json" \
-d '{
"serviceId": "service_abc123",
"pluginName": "key-auth",
"config": {
"required": true
}
}'

Requests must include the API key:

After authentication, the consumer is available:

// In plugin code
ctx.consumer.id; // Consumer ID
ctx.consumer.username; // Username
ctx.consumer.customId; // External ID
ctx.consumer.tags; // Tags

Use consumer identity for:

  • Rate limiting per consumer
  • Access control decisions
  • Request logging with identity

Bind plugins to specific consumers:

Terminal window
curl -X POST http://localhost:8080/api/plugins \
-H "Content-Type: application/json" \
-d '{
"consumerId": "consumer_abc123",
"pluginName": "rate-limit",
"config": {
"limit": 500
}
}'