Skip to content

Commit ec71216

Browse files
Merge pull request #438 from supertokens/fix/jwt-lifetime
fix: JWT lifetime setting issue
2 parents 5ea085f + 372491d commit ec71216

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## unreleased
99

10-
## [0.12.10] - 2023-09-28
10+
## [0.12.10] - 2023-09-01
1111

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

1415
## [0.12.9] - 2023-04-28
1516

supertokens_python/recipe/session/with_jwt/recipe_implementation.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ async def jwt_aware_update_access_token_payload(
159159
if decoded_payload is None or decoded_payload.get("exp") is None:
160160
raise Exception("Error reading JWT from session")
161161

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

173173
new_access_token_payload = await add_jwt_to_access_token_payload(
174174
access_token_payload=new_access_token_payload,

supertokens_python/recipe/session/with_jwt/session_class.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ async def update_access_token_payload(
7070
if decoded_payload is None or decoded_payload.get("exp") is None:
7171
raise Exception("Error reading JWT from session")
7272

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

8484
new_access_token_payload = await add_jwt_to_access_token_payload(
8585
access_token_payload=new_access_token_payload,

0 commit comments

Comments
 (0)