Merge pull request #107 from adriangzz/master

Fixes JWT_TOKEN_CLAIMS_SERIALIZER get attribute
This commit is contained in:
Michael 2020-07-07 23:29:17 -05:00 committed by GitHub
commit 3d72098845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -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": 'tests.test_api.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": 'tests.test_api.TESTTokenObtainPairSerializer'
}
)
def test_custom_jwt_claims_cookie_w_authentication(self):
payload = {
"username": self.USERNAME,

View File

@ -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