Skip to content

Commit b07e69b

Browse files
authored
Adjust jwt expiry error messages (#634)
* Adjust jwt expiry error messages * fix test
1 parent ee4949e commit b07e69b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

descope/auth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,17 @@ def _validate_token(
637637
audience=audience,
638638
leeway=self.jwt_validation_leeway,
639639
)
640-
except (ImmatureSignatureError, ExpiredSignatureError):
640+
except (ImmatureSignatureError):
641641
raise AuthException(
642642
400,
643643
ERROR_TYPE_INVALID_TOKEN,
644-
"Received Invalid token times error due to time glitch (between machines) during jwt validation, try to set the jwt_validation_leeway parameter (in DescopeClient) to higher value than 5sec which is the default",
644+
"Received Invalid token (nbf in future) during jwt validation. Error can be due to time glitch (between machines), try to set the jwt_validation_leeway parameter (in DescopeClient) to higher value than 5sec which is the default",
645+
)
646+
except (ExpiredSignatureError):
647+
raise AuthException(
648+
401,
649+
ERROR_TYPE_INVALID_TOKEN,
650+
"Received expired token (exp in past) during jwt validation. (sometimes can be due to time glitch (between machines), try to set the jwt_validation_leeway parameter (in DescopeClient) to higher value than 5sec which is the default)",
645651
)
646652

647653
claims["jwt"] = token

tests/test_descope_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def test_jwt_validation_leeway(self):
824824
self.assertEqual(cm.exception.status_code, 400)
825825
self.assertEqual(
826826
cm.exception.error_message,
827-
"Received Invalid token times error due to time glitch (between machines) during jwt validation, try to set the jwt_validation_leeway parameter (in DescopeClient) to higher value than 5sec which is the default",
827+
"Received Invalid token (nbf in future) during jwt validation. Error can be due to time glitch (between machines), try to set the jwt_validation_leeway parameter (in DescopeClient) to higher value than 5sec which is the default",
828828
)
829829

830830
def test_select_tenant(self):

0 commit comments

Comments
 (0)