Browse Source
♻️ Replace deprecated utcnow() with now(timezone.utc) in utils module (#1247)
pull/13907/head
Javier Álvarez
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
4 additions and
4 deletions
-
backend/app/core/security.py
-
backend/app/utils.py
|
|
@ -1,4 +1,4 @@ |
|
|
|
from datetime import datetime, timedelta |
|
|
|
from datetime import datetime, timedelta, timezone |
|
|
|
from typing import Any |
|
|
|
|
|
|
|
import jwt |
|
|
@ -13,7 +13,7 @@ ALGORITHM = "HS256" |
|
|
|
|
|
|
|
|
|
|
|
def create_access_token(subject: str | Any, expires_delta: timedelta) -> str: |
|
|
|
expire = datetime.utcnow() + expires_delta |
|
|
|
expire = datetime.now(timezone.utc) + expires_delta |
|
|
|
to_encode = {"exp": expire, "sub": str(subject)} |
|
|
|
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=ALGORITHM) |
|
|
|
return encoded_jwt |
|
|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
import logging |
|
|
|
from dataclasses import dataclass |
|
|
|
from datetime import datetime, timedelta |
|
|
|
from datetime import datetime, timedelta, timezone |
|
|
|
from pathlib import Path |
|
|
|
from typing import Any |
|
|
|
|
|
|
@ -98,7 +98,7 @@ def generate_new_account_email( |
|
|
|
|
|
|
|
def generate_password_reset_token(email: str) -> str: |
|
|
|
delta = timedelta(hours=settings.EMAIL_RESET_TOKEN_EXPIRE_HOURS) |
|
|
|
now = datetime.utcnow() |
|
|
|
now = datetime.now(timezone.utc) |
|
|
|
expires = now + delta |
|
|
|
exp = expires.timestamp() |
|
|
|
encoded_jwt = jwt.encode( |
|
|
|