From b15400e9c48a1e262a01fc043ae8ba552694a236 Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez Date: Thu, 2 Jul 2020 23:26:48 -0500 Subject: [PATCH 1/3] Fixes JWT_TOKEN_CLAIMS_SERIALIZER get attribute --- dj_rest_auth/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dj_rest_auth/utils.py b/dj_rest_auth/utils.py index 7011c8a..4ecfbc1 100644 --- a/dj_rest_auth/utils.py +++ b/dj_rest_auth/utils.py @@ -19,7 +19,14 @@ def default_create_token(token_model, user, serializer): def jwt_encode(user): from rest_framework_simplejwt.serializers import TokenObtainPairSerializer - TOPS = import_callable(getattr(settings, 'JWT_TOKEN_CLAIMS_SERIALIZER', TokenObtainPairSerializer)) + rest_auth_serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {}) + + JWTTokenClaimsSerializer = rest_auth_serializers.get( + 'JWT_TOKEN_CLAIMS_SERIALIZER', + TokenObtainPairSerializer + ) + + TOPS = import_callable(JWTTokenClaimsSerializer) refresh = TOPS.get_token(user) return refresh.access_token, refresh From 8e939e30ed0e8efb775e3d6214572a90c3e42d59 Mon Sep 17 00:00:00 2001 From: Aprimus Date: Tue, 7 Jul 2020 18:29:18 +0200 Subject: [PATCH 2/3] fix tests override settings for TokenObtainPairSerializer --- dj_rest_auth/tests/test_api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dj_rest_auth/tests/test_api.py b/dj_rest_auth/tests/test_api.py index c9141d9..b6bba96 100644 --- a/dj_rest_auth/tests/test_api.py +++ b/dj_rest_auth/tests/test_api.py @@ -628,7 +628,11 @@ class APIBasicTests(TestsMixin, TestCase): ] )) @override_settings(REST_SESSION_LOGIN=False) - @override_settings(JWT_TOKEN_CLAIMS_SERIALIZER = 'tests.test_api.TESTTokenObtainPairSerializer') + @override_settings( + REST_AUTH_SERIALIZERS={ + "JWT_TOKEN_CLAIMS_SERIALIZER": TESTTokenObtainPairSerializer + } + ) def test_custom_jwt_claims(self): payload = { "username": self.USERNAME, @@ -653,7 +657,11 @@ class APIBasicTests(TestsMixin, TestCase): ] )) @override_settings(REST_SESSION_LOGIN=False) - @override_settings(JWT_TOKEN_CLAIMS_SERIALIZER = 'tests.test_api.TESTTokenObtainPairSerializer') + @override_settings( + REST_AUTH_SERIALIZERS={ + "JWT_TOKEN_CLAIMS_SERIALIZER": TESTTokenObtainPairSerializer + } + ) def test_custom_jwt_claims_cookie_w_authentication(self): payload = { "username": self.USERNAME, From 12173461ac6ecaecb11e06b1ede570965bcda306 Mon Sep 17 00:00:00 2001 From: Aprimus Date: Tue, 7 Jul 2020 20:27:01 +0200 Subject: [PATCH 3/3] Change to string import instead of serializer class --- dj_rest_auth/tests/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dj_rest_auth/tests/test_api.py b/dj_rest_auth/tests/test_api.py index b6bba96..0f8ee42 100644 --- a/dj_rest_auth/tests/test_api.py +++ b/dj_rest_auth/tests/test_api.py @@ -630,7 +630,7 @@ class APIBasicTests(TestsMixin, TestCase): @override_settings(REST_SESSION_LOGIN=False) @override_settings( REST_AUTH_SERIALIZERS={ - "JWT_TOKEN_CLAIMS_SERIALIZER": TESTTokenObtainPairSerializer + "JWT_TOKEN_CLAIMS_SERIALIZER": 'tests.test_api.TESTTokenObtainPairSerializer' } ) def test_custom_jwt_claims(self): @@ -659,7 +659,7 @@ class APIBasicTests(TestsMixin, TestCase): @override_settings(REST_SESSION_LOGIN=False) @override_settings( REST_AUTH_SERIALIZERS={ - "JWT_TOKEN_CLAIMS_SERIALIZER": TESTTokenObtainPairSerializer + "JWT_TOKEN_CLAIMS_SERIALIZER": 'tests.test_api.TESTTokenObtainPairSerializer' } ) def test_custom_jwt_claims_cookie_w_authentication(self):