Skip to content
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

How to rate limit based on [user id/Token] #92

Open
alexjolig opened this issue Apr 21, 2022 · 3 comments
Open

How to rate limit based on [user id/Token] #92

alexjolig opened this issue Apr 21, 2022 · 3 comments

Comments

@alexjolig
Copy link

I need to implement the rate limitation based on JWT token. But in utils.py I can only see functions to get user's ip address. So is that possible to customize this. For example I can get the user info from request.state.user. How can I limit based on that?

@laurentS
Copy link
Owner

I think this issue #13 might be what you're after.

@alexjolig
Copy link
Author

alexjolig commented Apr 21, 2022

Thanks @laurentS . So if I want to limit based on JWT token, should I do it like this?

@limiter.limit(get_jwt_token):
def some_request(request: Request):
    pass

@mallorbc
Copy link

def get_limit_for_user():
    request = _request_ctx_var.get()
    key = request.cookies.get("key")

You have to pass values through cookies. In the body it will not work due to asyc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants