mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
API Limiting preventing Abuse
This commit is contained in:
parent
c5b02b866f
commit
77926cd047
1 changed files with 14 additions and 10 deletions
|
@ -26,12 +26,14 @@ limiter = Limiter(
|
|||
"100 per day",
|
||||
"5 per minute"
|
||||
],
|
||||
storge_uri="redis://localhost:6379"
|
||||
storage_options={"socket_connection_timeout": 30},
|
||||
storage_uri="redis://localhost:6379",
|
||||
storage_options={
|
||||
"socket_connect_timeout": 30,
|
||||
"retry_on_timeout": True # Retry logic
|
||||
},
|
||||
strategy="fixed-window-elastic-expiry"
|
||||
)
|
||||
|
||||
|
||||
def need_auth(f):
|
||||
@limiter.limit("5 per minute", key_func=lambda: request.authorization.username if request.authorization else get_remote_address())
|
||||
@wraps(f)
|
||||
|
@ -233,5 +235,7 @@ class TokenHandler(Resource):
|
|||
if not project:
|
||||
return "Not Found", 404
|
||||
|
||||
token = project.generate_token()
|
||||
return {"token": token}, 200
|
||||
token = project.generate_token(
|
||||
expiration=current_app.config.get('TOKEN_EXPIRY', 86400),
|
||||
)
|
||||
return {"token": token, "expires_in": 86400}, 200
|
||||
|
|
Loading…
Reference in a new issue