This repository was archived by the owner on May 26, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +9
-21
lines changed Expand file tree Collapse file tree 3 files changed +9
-21
lines changed Original file line number Diff line number Diff line change 45
45
'JWT_REFRESH_EXPIRATION_DELTA' : datetime .timedelta (days = 7 ),
46
46
47
47
'JWT_AUTH_HEADER_PREFIX' : 'JWT' ,
48
- 'JWT_AUTH_USER_MODEL' : settings .AUTH_USER_MODEL ,
49
48
'JWT_AUTH_COOKIE' : None ,
50
49
}
51
50
Original file line number Diff line number Diff line change 2
2
import uuid
3
3
import warnings
4
4
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
12
6
13
7
from calendar import timegm
14
8
from datetime import datetime
20
14
21
15
def jwt_get_secret_key (user_id = None ):
22
16
"""
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.
28
23
"""
29
24
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 )
36
27
key = str (api_settings .JWT_GET_USER_SECRET_KEY (user ))
37
28
return key
38
29
return api_settings .JWT_SECRET_KEY
Original file line number Diff line number Diff line change @@ -151,7 +151,6 @@ def test_post_form_failing_jwt_auth_changed_user_secret_key(self):
151
151
Ensure changin secret key on USER level makes tokens invalid
152
152
"""
153
153
# fine tune settings
154
- api_settings .JWT_AUTH_USER_MODEL = CustomUser
155
154
api_settings .JWT_GET_USER_SECRET_KEY = get_jwt_secret
156
155
157
156
tmp_user = CustomUser .
objects .
create (
email = '[email protected] ' )
@@ -174,7 +173,6 @@ def test_post_form_failing_jwt_auth_changed_user_secret_key(self):
174
173
self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
175
174
176
175
# revert api settings
177
- api_settings .JWT_AUTH_USER_MODEL = DEFAULTS ['JWT_AUTH_USER_MODEL' ]
178
176
api_settings .JWT_GET_USER_SECRET_KEY = DEFAULTS ['JWT_GET_USER_SECRET_KEY' ]
179
177
180
178
def test_post_invalid_token_failing_jwt_auth (self ):
You can’t perform that action at this time.
0 commit comments