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

fix: JWT lifetime setting issue #438

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## unreleased

## [0.12.10] - 2023-09-28
## [0.12.10] - 2023-09-01

- Add logic to retry network calls if the core returns status 429
- Fixes session recipe with jwt where the lifetime of the jwt is set to 1 in case it is `< 1`

## [0.12.9] - 2023-04-28

Expand Down
20 changes: 10 additions & 10 deletions supertokens_python/recipe/session/with_jwt/recipe_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ async def jwt_aware_update_access_token_payload(
if decoded_payload is None or decoded_payload.get("exp") is None:
raise Exception("Error reading JWT from session")

jwt_expiry = 1
if "exp" in decoded_payload:
exp = decoded_payload["exp"]
if exp > current_time_in_seconds:
# it can come here if someone calls this function well after
# the access token and the jwt payload have expired. In this case,
# we still want the jwt payload to update, but the resulting JWT should
# not be alive for too long (since it's expired already). So we set it to
# 1 second lifetime.
jwt_expiry = exp - current_time_in_seconds
jwt_expiry = decoded_payload.get("exp", 0) - current_time_in_seconds
# pylint: disable=consider-using-max-builtin
if jwt_expiry < 1:
# it can come here if someone calls this function well after
# the access token and the jwt payload have expired. In this case,
# we still want the jwt payload to update, but the resulting JWT should
# not be alive for too long (since it's expired already). So we set it to
# 1 second lifetime.
jwt_expiry = 1
# pylint: enable=consider-using-max-builtin

new_access_token_payload = await add_jwt_to_access_token_payload(
access_token_payload=new_access_token_payload,
Expand Down
20 changes: 10 additions & 10 deletions supertokens_python/recipe/session/with_jwt/session_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ async def update_access_token_payload(
if decoded_payload is None or decoded_payload.get("exp") is None:
raise Exception("Error reading JWT from session")

jwt_expiry = 1
if "exp" in decoded_payload:
exp = decoded_payload["exp"]
if exp > current_time_in_seconds:
# it can come here if someone calls this function well after
# the access token and the jwt payload have expired. In this case,
# we still want the jwt payload to update, but the resulting JWT should
# not be alive for too long (since it's expired already). So we set it to
# 1 second lifetime.
jwt_expiry = exp - current_time_in_seconds
jwt_expiry = decoded_payload.get("exp", 0) - current_time_in_seconds
# pylint: disable=consider-using-max-builtin
if jwt_expiry < 1:
# it can come here if someone calls this function well after
# the access token and the jwt payload have expired. In this case,
# we still want the jwt payload to update, but the resulting JWT should
# not be alive for too long (since it's expired already). So we set it to
# 1 second lifetime.
jwt_expiry = 1
# pylint: enable=consider-using-max-builtin

new_access_token_payload = await add_jwt_to_access_token_payload(
access_token_payload=new_access_token_payload,
Expand Down
Loading