Почему Sub - единственное, что возвращается в моей полезной нагрузке (Django pyjwt)?

Недавно я только начал использовать django. Я добавил некоторую аутентификацию для моего бэкенда. Проблема в следующем: когда я декодирую свой токен, возвращается только sub. Я хотел бы знать, почему. Вот мой файл authentication.py:

from rest_framework.authentication import BasicAuthentication
from rest_framework.exceptions import PermissionDenied
from django.contrib.auth import get_user_model
from django.conf import settings
import jwt
User = get_user_model()

class JWTAuthentication(BasicAuthentication):

def authenticate(self, request):
    header = request.headers.get('Authorization')

    if not header:
        return None

    if not header.startswith('Bearer'):
        raise PermissionDenied({'message': 'Invalid authorization header!'})

    token = header.replace('Bearer', '')

    try:
        payload = jwt.decode(token, settings.SECRET_KEY, algorithms=['HS256'])
        user = User.objects.get(pk=payload.get('sub'))

    except jwt.exceptions.InvalidTokenError:
        raise PermissionDenied({'message':'Invalid token'})

    except User.DoesNotExist:
        raise PermissionDenied({'message':'User not found'})

    return (user, token)

Вот моя модель:

class CustomUser(AbstractUser):
username = models.CharField(max_length=200, null=True, blank=True)
first_name = models.CharField(max_length=240)
last_name = models.CharField(max_length=240)
email = models.EmailField(_('email address'), unique=True)
bio = models.TextField(null=True, blank=True)

objects = UserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']
Вернуться на верх