How to retrieve current user from request.headers while ratelimiting the endpoint?
See original GitHub issueFor ratelimiting the endpoint I want to use two approaches i)based on IP address (unprotected endpoint, no JWT access token)
def get_remote_address(request: Request) -> str:
"""
Returns the ip address for the current request (or 127.0.0.1 if none found)
"""
return request.client.host or "127.0.0.1"
It works fine
2 ) based on current user, current user has to be retrieved from JWT access token. JWT access token is created using this fastapi-jwt-auth and user is in get-jwt-subject.
from starlette.requests import Request
from fastapi_jwt_auth import AuthJWT
def get_user_from_headers(request: Request):
if 'authorization' in request.headers:
current_user = AuthJWT.get_jwt_subject()
print(current_user)
return current_user
else:
return get_remote_address
Doing this, I couldn’t find current-user. How to find current_user if request.headers has authorization?
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Rate limiting your RESTful API - Medium
Rate limiting : use X-RateLimit-* HTTP headers and 429 status code ... When a rate limit is reached, your API should return the...
Read more >RateLimit Header Fields for HTTP - IETF
On the web we can find many different rate-limit headers, usually containing the number of allowed requests in a given time window, and...
Read more >User and IP rate limits - GitLab Docs
Select Enable unauthenticated API request rate limit. ... Otherwise, you must trust your users to not set that header and bypass the GitLab ......
Read more >Understanding and implementing rate limiting in Node.js
In general terms, it allows us to control the rate at which user requests are processed by our server. In this article, we...
Read more >Rate Limit Policy - Auth0
For the up-to-date information on rate limits, you can review the HTTP response headers returned from rate-limited endpoints. API requests to ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you
Thank you very much