from rest_framework_simplejwt.serializers import TokenObtainPairSerializer class MyTokenObtainPairSerializer(TokenObtainPairSerializer): @classmethod def get_token(cls, user): """ Get the token for the user and add custom claims, such as 'username'. """ token = super(MyTokenObtainPairSerializer, cls).get_token(user) token['username'] = user.username return token