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 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
Original file line number Diff line number Diff line change 22import uuid
33import 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
137from calendar import timegm
148from datetime import datetime
2014
2115def 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
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):
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 = 'b@example.com' )
@@ -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 ):
You can’t perform that action at this time.
0 commit comments