feat: as a user I want to use the claim in JWT token as a key in limit-count
plugin.
#11918
Labels
enhancement
New feature or request
limit-count
plugin.
#11918
Description
I would like to enhance the
limit-count
plugin to support using a jwt-claim value as akey
.Problem Statement
Currently, the
limit-count
plugin supports only static keys like"var", "var_combination", "constant"
. However, many real-world scenarios require dynamic rate limiting based on contexts like specific users, tenants, or roles. This capability is particularly relevant when using JWT tokens, as they can contain such contextual information.Importance
Adding support for JWT claims as keys in the
limit-count
plugin provides more flexibility in managing API usage. This feature makes it possible to enforce rate limits dynamically based on JWT content, thereby catering to various business use cases such as:Solution Approach
To achieve this, I propose the following enhancements:
JWT Claim-Based Key Type
A new key type,
jwt_claim
, will be introduced. When this key type is selected, the plugin will dynamically extract the specified claim from the JWT token using the in-house JWT library:If
key_type
is configured as"jwt_claim"
, the plugin will decode the token and use the claim value as the rate-limiting key:Here,
conf.key
specifies the claim field to be used for rate limiting.Optional Enhancement: Remaining Time in Error Messages
To improve the user experience, the plugin can dynamically include the remaining reset time in the error message. If
$reset_in
is present in therejected_msg
configuration, it will be replaced with the actual time remaining:Example Output:
Although the headers already provide reset time details, including it in the error message makes the information more accessible and user-friendly.
Benefits
Do you think this change is suitable for a PR?
The text was updated successfully, but these errors were encountered: