Fix utcnow deprecation warning (#1369)

This commit is contained in:
Matthew D. Scholefield
2024-03-11 05:25:36 -07:00
committed by GitHub
parent bb1b0d759e
commit a4287b8586

View File

@ -1,4 +1,4 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
import jwt import jwt
@ -22,7 +22,7 @@ def generate_jwt(
) -> str: ) -> str:
payload = data.copy() payload = data.copy()
if lifetime_seconds: if lifetime_seconds:
expire = datetime.utcnow() + timedelta(seconds=lifetime_seconds) expire = datetime.now(timezone.utc) + timedelta(seconds=lifetime_seconds)
payload["exp"] = expire payload["exp"] = expire
return jwt.encode(payload, _get_secret_value(secret), algorithm=algorithm) return jwt.encode(payload, _get_secret_value(secret), algorithm=algorithm)