Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 5983e57

Browse files
committed
cleanup as suggested - removed api_settings.JWT_AUTH_USER_MODEL
1 parent a00d589 commit 5983e57

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

rest_framework_jwt/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
4646

4747
'JWT_AUTH_HEADER_PREFIX': 'JWT',
48-
'JWT_AUTH_USER_MODEL': settings.AUTH_USER_MODEL,
4948
'JWT_AUTH_COOKIE': None,
5049
}
5150

rest_framework_jwt/utils.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
import uuid
33
import warnings
44

5-
from six import string_types
6-
7-
try:
8-
from django.db.models.loading import get_model
9-
except ImportError:
10-
from django.apps import apps
11-
get_model = apps.get_model
5+
from django.contrib.auth import get_user_model
126

137
from calendar import timegm
148
from datetime import datetime
@@ -20,19 +14,16 @@
2014

2115
def jwt_get_secret_key(user_id=None):
2216
"""
23-
For enchanced security you may use secret key on user itself.
24-
This way you have an option to logout only this user if:
25-
- token is compromised
26-
- password is changed
27-
- etc.
17+
For enchanced security you may use secret key on user itself.
18+
19+
This way you have an option to logout only this user if:
20+
- token is compromised
21+
- password is changed
22+
- etc.
2823
"""
2924
if api_settings.JWT_GET_USER_SECRET_KEY:
30-
if isinstance(api_settings.JWT_AUTH_USER_MODEL, string_types):
31-
parts = api_settings.JWT_AUTH_USER_MODEL.rsplit('.', 1)
32-
Account = get_model(parts[0], parts[1])
33-
else:
34-
Account = api_settings.JWT_AUTH_USER_MODEL
35-
user = Account.objects.get(pk=user_id)
25+
User = get_user_model() # noqa: N806
26+
user = User.objects.get(pk=user_id)
3627
key = str(api_settings.JWT_GET_USER_SECRET_KEY(user))
3728
return key
3829
return api_settings.JWT_SECRET_KEY

tests/test_authentication.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def test_post_form_failing_jwt_auth_changed_user_secret_key(self):
151151
Ensure changin secret key on USER level makes tokens invalid
152152
"""
153153
# fine tune settings
154-
api_settings.JWT_AUTH_USER_MODEL = CustomUser
155154
api_settings.JWT_GET_USER_SECRET_KEY = get_jwt_secret
156155

157156
tmp_user = CustomUser.objects.create(email='[email protected]')
@@ -174,7 +173,6 @@ def test_post_form_failing_jwt_auth_changed_user_secret_key(self):
174173
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
175174

176175
# revert api settings
177-
api_settings.JWT_AUTH_USER_MODEL = DEFAULTS['JWT_AUTH_USER_MODEL']
178176
api_settings.JWT_GET_USER_SECRET_KEY = DEFAULTS['JWT_GET_USER_SECRET_KEY']
179177

180178
def test_post_invalid_token_failing_jwt_auth(self):

0 commit comments

Comments
 (0)