Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jwt/api_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
import warnings
from calendar import timegm
from collections.abc import Container, Iterable, Sequence
from datetime import datetime, timedelta, timezone
from typing import TYPE_CHECKING, Any, Union, cast
Expand Down Expand Up @@ -125,9 +124,9 @@ def encode(
# Payload
payload = payload.copy()
for time_claim in ["exp", "iat", "nbf"]:
# Convert datetime to a intDate value in known time-format claims
# Convert datetime to a float value in known time-format claims
if isinstance(payload.get(time_claim), datetime):
payload[time_claim] = timegm(payload[time_claim].utctimetuple())
payload[time_claim] = payload[time_claim].timestamp()
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from timegm(utctimetuple()) to timestamp() introduces a behavioral difference for naive datetime objects (datetimes without timezone information). The old implementation treated naive datetimes as UTC, while timestamp() treats them as local time. This could be a breaking change for users passing naive datetime objects. Consider adding validation to require timezone-aware datetime objects, or document this behavioral change clearly.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change enables microsecond precision in timestamp encoding, but there's no test to verify this new behavior. Consider adding a test that encodes a datetime with microseconds and verifies that the microseconds are preserved in the decoded payload. For example, a test similar to test_encode_datetime but using a datetime with microseconds like datetime(2025, 1, 1, 0, 0, 0, 123456, timezone.utc).

Copilot uses AI. Check for mistakes.

# Issue #1039, iss being set to non-string
if "iss" in payload and not isinstance(payload["iss"], str):
Expand Down
Loading