From 20896030d7681ba00815ae659fafc9897cdde286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 27 Jun 2024 11:26:44 +0200 Subject: [PATCH] fastapi_auth_partner: raise the right http code when cookies is invalid --- fastapi_auth_partner/dependencies.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fastapi_auth_partner/dependencies.py b/fastapi_auth_partner/dependencies.py index 7aef0b44c..8fe43da9f 100644 --- a/fastapi_auth_partner/dependencies.py +++ b/fastapi_auth_partner/dependencies.py @@ -48,9 +48,13 @@ def __call__( elif fastapi_auth_partner: directory = endpoint.sudo().directory_id - vals = URLSafeTimedSerializer(directory.cookie_secret_key).loads( - fastapi_auth_partner, max_age=directory.cookie_duration * 60 - ) + try: + vals = URLSafeTimedSerializer(directory.cookie_secret_key).loads( + fastapi_auth_partner, max_age=directory.cookie_duration * 60 + ) + except Exception as e: + _logger.error("Invalid cookies error %s", e) + raise HTTPException(status_code=HTTP_401_UNAUTHORIZED) from e if vals["did"] == directory.id and vals["pid"]: partner = env["res.partner"].browse(vals["pid"]).exists() if partner: