From 172bfd934982bf2a7bf0254fc9a8945beca74cb7 Mon Sep 17 00:00:00 2001 From: Muhammad Sameer Amin <35958006+sameeramin@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:42:36 +0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactored=20code=20to=20u?= =?UTF-8?q?se=20encryption=20algorithm=20name=20from=20settings=20for=20co?= =?UTF-8?q?nsistency=20(#1160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- backend/app/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/app/utils.py b/backend/app/utils.py index 38cff81..ac029f6 100644 --- a/backend/app/utils.py +++ b/backend/app/utils.py @@ -9,6 +9,7 @@ import jwt from jinja2 import Template from jwt.exceptions import InvalidTokenError +from app.core import security from app.core.config import settings logging.basicConfig(level=logging.INFO) @@ -107,14 +108,16 @@ def generate_password_reset_token(email: str) -> str: encoded_jwt = jwt.encode( {"exp": exp, "nbf": now, "sub": email}, settings.SECRET_KEY, - algorithm="HS256", + algorithm=security.ALGORITHM, ) return encoded_jwt def verify_password_reset_token(token: str) -> str | None: try: - decoded_token = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"]) + decoded_token = jwt.decode( + token, settings.SECRET_KEY, algorithms=[security.ALGORITHM] + ) return str(decoded_token["sub"]) except InvalidTokenError: return None