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 user_id type mismatch when user claim is not pk #851

Merged

Conversation

jdg-journeyfront
Copy link
Contributor

Regarding changes made at https://github.com/jazzband/djangorestframework-simplejwt/pull/806/files

We're using a USER_ID_CLAIM that is neither the primary key field nor is it the
same type as the primary key, (tests are using the email column but we use a
UUID column secondary key) and these previous changes fail at this point when
attempting to create an OutstandingToken, because it assumes that the ID pulled
out of the token claims is usable as the database key for a user.

So to mitigate this gets the user from the database using the USER_ID_FIELD
setting and uses that in the get_or_create call.

token.blacklist()
outstanding_token = OutstandingToken.objects.get(token=token)
self.assertEqual(outstanding_token.user, self.user)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add a test which will ensure that the User.DoesNotExist error is properly handled when the user does not exist anymore?

E.g:

  1. create the token,
  2. delete self.user object with self.user.delete()
  3. call token.blacklist()
  4. assert that there is a BlacklistedToken record

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry I just saw your review just now. I'll get on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've added that test.

@lalit-sh
Copy link

Hi, When can we expect this to be merged ?

Regarding changes made at https://github.com/jazzband/djangorestframework-simplejwt/pull/806/files

We're using a USER_ID_CLAIM that is neither the primary key field nor is it the
same type as the primary key, and these previous changes fail at this point
when attempting to create an OutstandingToken, because it assumes that the ID
pulled out of the token claims is usable as the database key for a user.

So to mitigate this gets the user from the database using the USER_ID_FIELD
setting and uses that in the get_or_create call.

Also include a test of handling the case where the user is deleted when the
token is blacklisted.
@cellofellow cellofellow force-pushed the fix-user-id-type-mismatch branch from 834a89d to 49b84ed Compare February 5, 2025 21:25
@vgrozdanic vgrozdanic merged commit a01cb8b into jazzband:master Feb 6, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants