title: Customizing JWT response from django-rest-framework-simplejwt
body: <p>I'm setting up Django to send a JWT Response as opposed to a view. I tried using django-rest-framework-simplejwt.</p>
  <p>Provided in this framework, there is a function <code>TokenObtainPairView.as_view()</code> that returns a pair of jwt. I need to return the access token with another Json response as opposed to the two tokens provided.</p>
  <p>Ideally I would like one JsonResponse that contains an access token that is the same as this one: <code>TokenObtainPairView.as_view()</code>.</p>
  <p>I tried creating my own view which is provided below.</p>
  <p><strong>UPDATE:</strong> Provided in Settings.py</p>
  <pre><code>SIMPLE_JWT = {
      'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
      'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
      'ROTATE_REFRESH_TOKENS': False,
      'BLACKLIST_AFTER_ROTATION': True,
  
      'ALGORITHM': 'HS256',
      'SIGNING_KEY': SECRET_KEY,
      'VERIFYING_KEY': None,
  
      'AUTH_HEADER_TYPES': ('Bearer',),
      'USER_ID_FIELD': 'id',
      'USER_ID_CLAIM': 'user_id',
  
      'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
      'TOKEN_TYPE_CLAIM': 'token_type',
  
      'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
      'SLIDING_TOKEN_LIFETIME': timedelta(days=1),
      'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
  }
  </code></pre>
  <p>Login URL Path</p>
  <pre><code>urlpatterns = [
      path('auth/', views.LoginView.as_view()),
  ]
  </code></pre>
  <p>LoginView I created</p>
  <pre><code>class LoginView(APIView):
      permission_classes = (AllowAny,)
  
      def post(self, request, *args, **kwargs):
          username = request.data['username']
          password = request.data['password']
  
          user = authenticate(username=username, password=password)
  
          if user is not None:
              payload = {
                  'user_id': user.id,
                  'exp': datetime.now(),
                  'token_type': 'access'
              }
  
              user = {
                  'user': username,
                  'email': user.email,
                  'time': datetime.now().time(),
                  'userType': 10
              }
  
              token = jwt.encode(payload, SECRET_KEY).decode('utf-8')
              return JsonResponse({'success': 'true', 'token': token, 'user': user})
  
          else:
              return JsonResponse({'success': 'false', 'msg': 'The credentials provided are invalid.'})
  </code></pre>
  <p>Pattern provided by framework.</p>
  <pre><code>urlpatterns = [
  ...
  path('token/', TokenObtainPairView.as_view()),
  ...
  ]
  </code></pre>
  <p>It returns this token</p>
  <blockquote>
  <p>eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTQ5NDk3NDQ2LCJqdGkiOiI3YmU4YzkzODE4MWI0MmJlYTFjNDUyNDhkNDZmMzUxYSIsInVzZXJfaWQiOiIwIn0.xvfdrWf26g4FZL2zx3nJPi7tjU6QxPyBjq-vh1fT0Xs</p>
  <p>eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTU0OTQ5NzQ0NiwianRpIjoiOTNhYzkxMjU5NmZkNDYzYjg2OGQ0ZTM2ZjZkMmJhODciLCJ1c2VyX2lkIjoiMCJ9.dOuyuFuMjkVIRI2_UcXT8_alCjlXNaiRJx8ehQDIBCg</p>
  </blockquote>
  <p>If you go to <a href="https://jwt.io/" rel="noreferrer">https://jwt.io/</a> you will see what's returned</p>