Browse Source
♻️ Refactored code to use encryption algorithm name from settings for consistency (#1160)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
pull/13907/head
Muhammad Sameer Amin
10 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
5 additions and
2 deletions
-
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 |
|
|
|