Skip to content
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

Timezone-aware datetime Object Support #325

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Flat-Irons
Copy link

Allows for datetime objects that are timezone-aware to be used for time-based claims: 'exp' and 'nbf' when making a JWT object, converting them to integer unix timestamps.

Flat-Irons and others added 2 commits June 27, 2023 00:47
Added ability to use datetime objects that are timezone aware for tim…
Copy link
Member

@simo5 simo5 left a comment

Choose a reason for hiding this comment

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

Nits,
also please cleanup the commits, needs sign-off line.
Also please squash into a single comment w/o merge stuff and provide a commit message.

# Check for datetime objects
if 'exp' in claims and isinstance(claims['exp'], datetime):
# Check if timezone aware
claims['exp'] = self._check_and_convert_dt(claims['exp'], 'exp')
Copy link
Member

Choose a reason for hiding this comment

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

I do not think we should modify the array being passed in.
We should instead make a copy in self.claims and modify them there

return dt_timestamp
else:
raise ValueError(
f"'{claim_prop}' datetime object must be timezone aware"
Copy link
Member

Choose a reason for hiding this comment

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

Why does it need to be timezone-aware? Can't we just assume UTC if no timezone is set?

@simo5
Copy link
Member

simo5 commented Jun 27, 2023

Please add a test that verifies this si working properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants