-
-
Notifications
You must be signed in to change notification settings - Fork 754
Fix #1126: Fix microseconds lose on jwt.encode for known time claims #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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() | ||
|
||
|
|
||
| # Issue #1039, iss being set to non-string | ||
| if "iss" in payload and not isinstance(payload["iss"], str): | ||
|
|
||
There was a problem hiding this comment.
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.