♻️ Refactored code to use encryption algorithm name from settings for consistency (#1160)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:

committed by
GitHub

parent
79883c879f
commit
172bfd9349
@@ -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
|
||||
|
Reference in New Issue
Block a user