Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 2 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ def for_user(cls: type[T], user: AuthUser) -> T:
)

user_id = getattr(user, api_settings.USER_ID_FIELD)
if not isinstance(user_id, int):
user_id = str(user_id)
user_id = str(user_id)

token = cls()
token[api_settings.USER_ID_CLAIM] = user_id
Expand Down
7 changes: 5 additions & 2 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ def test_for_user(self):
token = MyToken.for_user(self.user)

user_id = getattr(self.user, api_settings.USER_ID_FIELD)
if not isinstance(user_id, int):
user_id = str(user_id)
user_id = str(user_id)

self.assertEqual(token[api_settings.USER_ID_CLAIM], user_id)

Expand All @@ -404,6 +403,10 @@ def test_get_token_backend(self):

self.assertEqual(token.get_token_backend(), token_backend)

def test_token_user_id_claim_should_always_be_string(self):
token = MyToken.for_user(self.user)
self.assertIsInstance(token[api_settings.USER_ID_CLAIM], str)


class TestSlidingToken(TestCase):
def test_init(self):
Expand Down
Loading