stefanprodan / AspNetCoreRateLimit

ASP.NET Core rate limiting middleware
MIT License
3.12k stars 445 forks source link

[Question] RateLimiting on a MultiTenant Service #183

Open mohi41 opened 3 years ago

mohi41 commented 3 years ago

Hi I have a multi-tenant service and I want to enforce different rules (and quotas) based on the [tenantId + ClientId]. Each tenant should have its own rules. Any suggestion?

AntonyCorbett commented 3 years ago

@melmi I think you would need to create your own custom config class (inheriting from RateLimitConfiguration) and register it in your services. Also your own IClientResolveContributor implementation in order to resolve the client ID.

rebeccapowell commented 3 years ago

This might be a useful resource in that case, assuming for example you are using OAuth client credentials flow, you can extract the tenant from the user claims:

https://blog.elmah.io/rate-limiting-api-requests-with-asp-net-core-and-aspnetcoreratelimit/