I have a proxied user model:
class TheDude(User):
class Meta:
proxy = True
And I'm using the Django REST framework JWT to do JWT auth in the REST API.
I'd like to get the user object from the request but currently it's a User object. Because it's proxied I can't use AUTH_USER_MODEL. I've tried doing a middleware component to override the user in the request but it's not set at that stage. I've also tried using JWT_RESPONSE_PAYLOAD_HANDLER however my function isn't called so I can't set it there either.
If I want to be able to get TheDude object when I call request.user instead of User in my views, how would I do this while authing using the REST framework JWT Auth library?
EDIT
I've added
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'myapp.authentication.MyCustomJWTAuthentication',
)
...
}
to my settings.py and my
class MyCustomJWTAuthentication(JWTAuthentication):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_model = TheDude
Which is called correctly however when I get the user from request in my serialiser, it's still of type User and not TheDude
class TestSerializer(serializers.ModelSerializer):
user_test = serializers.SerializerMethodField('get_user_test')
def get_user_test(self, obj):
print(type(self.context['request'].user))