-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Token, User}-dependent rate limit control #205
Comments
@brunolnetto this is supported with slowapi. You can provide a I.e. just using the bearer token as a key for rate limiting could be done with: from fastapi import Request
from slowapi import Limiter
def api_key_from_request(request: Request):
auth = request.headers.get("authorization")
user_id = get_user_id_from_auth(auth)
return user_id
limiter = Limiter(key_func=api_key_from_request)
... |
Is there some way to alternate between provided key and default key, like IP? I mean, not every route is key-protected. |
Sure, check out the default utility functions that support IP based rate limiting: https://slowapi.readthedocs.io/en/latest/api/#utility-functions And you can override with per route/decorator key functions, depending on the need for each route. |
Sorry for furher requesting explanation, but what precisely is the difference between functions |
Probably better served for discussions, but you can view the implementation here. TLDR:
|
I added a pull request to remove repeated code. May you review and merge? :-) |
I'm not a maintainer of this project, so cannot help with that. Just a user. |
@ecly thanks for taking the time to reply! @brunolnetto I've authorized CI on your PR, thanks for sending it in. |
CI is till failing because of command run |
Describe the bug
This is not a bug description. In fact, I would like to know if the use case for authentication-dependent (i.e. JWT token, for example) is covered by this library. The use case is as follows:
The text was updated successfully, but these errors were encountered: