kopieczek.dev
kopieczek.dev

Reputation: 732

Azure ApiManagement - limit requests for certain user

Is there any way to increase requests limit for a certain users?

We have global rate-limit-by-key policy and I would like to allow one customer to call API more frequently.

<rate-limit-by-key 
    calls="120" 
    renewal-period="60" 
    counter-key="@(context.Subscription.Id)" />

Upvotes: 0

Views: 782

Answers (1)

Joey Cai
Joey Cai

Reputation: 20127

If an end user is authenticated, then a throttling key can be generated based on information that uniquely identifies that user.

<rate-limit-by-key calls="10"
    renewal-period="60"
    counter-key="@(context.Request.Headers.GetValueOrDefault("Authorization","").AsJwt()?.Subject)" />

This example shows how to extract the Authorization header, convert it to JWT object and use the subject of the token to identify the user and use that as the rate limiting key. If the user identity is stored in the JWT as one of the other claims, then that value could be used in its place.

For more details, you could refer to this article.

Upvotes: 1

Related Questions