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 don't usually write issues, so bear with me. We noticed our dev environment suddenly wasn't letting anyone log in. It turns out it's because PyJWT updated to 2.10.0, and that began enforcing that subject be a string.
In this section, the code only sometimes converts the id to a string
>/usr/local/lib/python3.11/site-packages/rest_framework_simplejwt/tokens.py(208)
197 @classmethod198deffor_user(cls, user: AuthUser) ->"Token":
199""" 200 Returns an authorization token for the given user that will be provided 201 after authenticating the user's credentials. 202 """204user_id=getattr(user, api_settings.USER_ID_FIELD)
205ifnotisinstance(user_id, int):
206user_id=str(user_id)
That returns a seemingly fine token. However, when trying to use it, downstream from here
>/usr/local/lib/python3.11/site-packages/rest_framework_simplejwt/tokens.py(56)
37def__init__(self, token: Optional["Token"] =None, verify: bool=True) ->None:
38""" 39 !!!! IMPORTANT !!!! MUST raise a TokenError with a user-facing error 40 message if the given token is invalid, expired, or otherwise not safe 41 to use. 42 """43ifself.token_typeisNoneorself.lifetimeisNone:
44raiseTokenError(_("Cannot create token with no type or lifetime"))
4546self.token=token47self.current_time=aware_utcnow()
4849# Set up token50iftokenisnotNone:
51# An encoded token was provided52token_backend=self.get_token_backend()
5354# Decode token55try:
56->self.payload=token_backend.decode(token, verify=verify)
57exceptTokenBackendError:
58raiseTokenError(_("Token is invalid or expired"))
59
287def_validate_sub(self, payload: dict[str, Any], subject=None) ->None:
288""" 289 Checks whether "sub" if in the payload is valid ot not. 290 This is an Optional claim 291 292 :param payload(dict): The payload which needs to be validated 293 :param subject(str): The subject of the token 294 """295296if"sub"notinpayload:
297return298299ifnotisinstance(payload["sub"], str):
300->raiseInvalidSubjectError("Subject must be a string")
(Pdb++) payload
{'token_type': 'access', 'exp': 1732058200, 'iat': 1732054600, 'jti': '537bae19596045f09177d29195d2ed71', 'sub': 3}
because sub is 3 and not "3", i guess.
Maybe if simplejwt passes verify_sub: False when it calls jwt.decode in /usr/local/lib/python3.11/site-packages/rest_framework_simplejwt/backends.py(139) it would work? PyJWT seems to merge options
I had the same issue today.
In my Flask project I use a package flask_jwt_extended which has PyJWT dependency.
I set PyJWT version to 2.8.0 in a requirements.txt to prevent uploading the latest version (2.10.0) of PyJWT inside CI/CD builds.
I don't usually write issues, so bear with me. We noticed our dev environment suddenly wasn't letting anyone log in. It turns out it's because PyJWT updated to 2.10.0, and that began enforcing that
subject
be a string.In this section, the code only sometimes converts the id to a string
That returns a seemingly fine token. However, when trying to use it, downstream from here
vv
All the way down in
it blows up
because
sub
is3
and not"3"
, i guess.Maybe if simplejwt passes
verify_sub: False
when it calls jwt.decode in/usr/local/lib/python3.11/site-packages/rest_framework_simplejwt/backends.py(139)
it would work? PyJWT seems to merge optionsThis seems to stem from the changes added in jpadilla/pyjwt#1005
The text was updated successfully, but these errors were encountered: