You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've used UUID7 from your package as an ID (token) for user session - I want to use time stored in the token as a creation timestamp directly. And I want to invalidate the token after some time (a day). So what I did was to fetch .time from the UUID and compare it to current time.timestamp. Problem is - on different platforms UUID.time returns different order of values. As a workaround I have to divide by certain value to make it possible to compare.
Final function currently looks like this:
defcheck_token_expired(uuid: UUID, session_timeout_seconds: int) ->bool:
"""Check if session has expired by uuid v7 timestamp. Returns True if session IS expired."""assertisinstance(uuid, UUID)
now_unix=datetime.now().timestamp()
uuid_time=uuid.timeifos.name=='posix':
uuid_time=uuid_time/1000ifos.name=='nt':
uuid_time=uuid_time/1000000000return (now_unix-uuid_time) >session_timeout_seconds
Those os.name == ... comparissons look wrong to me. And it looks like the difference comes from uuid.time, not from datetime.now().timestamp(). Could you help checking this please?
Platforms I've tested on are Windows 10 and WSL with Ubuntu.
The text was updated successfully, but these errors were encountered:
For example the UUID7 .time implementation of this library has changed the returned values from nanosecond precision to millisecond precision when the official draft made the same change.
Sorry, I forgot to update this issue. It's no longer relevant. I'm not sure what, when and where (probably Python update) was changed, but one day there was no longer a difference in readings, so I could remove that workaround.
First of all, thank you for the package!
I've used UUID7 from your package as an ID (token) for user session - I want to use time stored in the token as a creation timestamp directly. And I want to invalidate the token after some time (a day). So what I did was to fetch .time from the UUID and compare it to current time.timestamp. Problem is - on different platforms UUID.time returns different order of values. As a workaround I have to divide by certain value to make it possible to compare.
Final function currently looks like this:
Those
os.name == ...
comparissons look wrong to me. And it looks like the difference comes fromuuid.time
, not fromdatetime.now().timestamp()
. Could you help checking this please?Platforms I've tested on are Windows 10 and WSL with Ubuntu.
The text was updated successfully, but these errors were encountered: