Skip to content

Commit

Permalink
♻️ Refactored code to use encryption algorithm name from settings for…
Browse files Browse the repository at this point in the history
… consistency (#1160)

Co-authored-by: Sebastián Ramírez <[email protected]>
  • Loading branch information
sameeramin and tiangolo authored Sep 27, 2024
1 parent 79883c8 commit 172bfd9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions backend/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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)
Expand Down Expand Up @@ -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

0 comments on commit 172bfd9

Please sign in to comment.