Skip to content

Commit

Permalink
fix: use explicit UTC timezone instead of datetime.utcnow (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
brouberol authored Nov 2, 2023
1 parent e901cb9 commit 60812d4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion fastapi_jwt/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
jwt = None # type: ignore[assignment]


def utcnow():
try:
from datetime import UTC
except ImportError: # pragma: nocover
# UTC was added in python 3.12, as datetime.utcnow was
# marked for deprecation.
return datetime.utcnow()
else:
return datetime.now(UTC)


__all__ = [
"JwtAuthorizationCredentials",
"JwtAccessBearer",
Expand Down Expand Up @@ -132,7 +143,7 @@ def _generate_payload(
unique_identifier: str,
token_type: str,
) -> Dict[str, Any]:
now = datetime.utcnow()
now = utcnow()

return {
"subject": subject.copy(), # main subject
Expand Down

0 comments on commit 60812d4

Please sign in to comment.