alisaifee / limits

Rate limiting using various strategies and storage backends such as redis & memcached
https://limits.readthedocs.org
MIT License
423 stars 58 forks source link

How to limit based on token? #122

Closed alexjolig closed 2 years ago

alexjolig commented 2 years ago

Hi, how can I implement rate limit based on user id or token? I couldn't find the code where it checks IP to replace it with token.

alisaifee commented 2 years ago

What you limit by is not implemented in this library - it is left for the downstream client (for example Flask-Limiter). You can see some examples in the quickstart where consuming a limit (RateLimiter.hit) takes any number of identifiers which are combined to form the key to limit by.

alexjolig commented 2 years ago

Thanks @alisaifee . Seems like adding it to hit like this works to limit based on token, email, user id ,etc...

moving_window.hit(rate_limit_item, email)

alisaifee commented 2 years ago

Yeap! that's right.