Repository: jazzband/django-oauth-toolkit

Issue:
Change JSON based HttpResponse to JSONResponse
https://github.com/jazzband/django-oauth-toolkit/blob/d90bb348f00886ae8321f8194f6275be9aa08f80/oauth2_provider/views/introspect.py#L48-L56

Any reason not to use `django.http.JSONResponse`?


Discussion:
valid point to use jsonresponse

Resolving patch:
diff --git a/oauth2_provider/models.py b/oauth2_provider/models.py
--- a/oauth2_provider/models.py
+++ b/oauth2_provider/models.py
@@ -563,56 +563,56 @@ class Meta(AbstractIDToken.Meta):
 
 
 def get_application_model():
-    """ Return the Application model that is active in this project. """
+    """Return the Application model that is active in this project."""
     return apps.get_model(oauth2_settings.APPLICATION_MODEL)
 
 
 def get_grant_model():
-    """ Return the Grant model that is active in this project. """
+    """Return the Grant model that is active in this project."""
     return apps.get_model(oauth2_settings.GRANT_MODEL)
 
 
 def get_access_token_model():
-    """ Return the AccessToken model that is active in this project. """
+    """Return the AccessToken model that is active in this project."""
     return apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
 
 
 def get_id_token_model():
-    """ Return the AccessToken model that is active in this project. """
+    """Return the AccessToken model that is active in this project."""
     return apps.get_model(oauth2_settings.ID_TOKEN_MODEL)
 
 
 def get_refresh_token_model():
-    """ Return the RefreshToken model that is active in this project. """
+    """Return the RefreshToken model that is active in this project."""
     return apps.get_model(oauth2_settings.REFRESH_TOKEN_MODEL)
 
 
 def get_application_admin_class():
-    """ Return the Application admin class that is active in this project. """
+    """Return the Application admin class that is active in this project."""
     application_admin_class = oauth2_settings.APPLICATION_ADMIN_CLASS
     return application_admin_class
 
 
 def get_access_token_admin_class():
-    """ Return the AccessToken admin class that is active in this project. """
+    """Return the AccessToken admin class that is active in this project."""
     access_token_admin_class = oauth2_settings.ACCESS_TOKEN_ADMIN_CLASS
     return access_token_admin_class
 
 
 def get_grant_admin_class():
-    """ Return the Grant admin class that is active in this project. """
+    """Return the Grant admin class that is active in this project."""
     grant_admin_class = oauth2_settings.GRANT_ADMIN_CLASS
     return grant_admin_class
 
 
 def get_id_token_admin_class():
-    """ Return the IDToken admin class that is active in this project. """
+    """Return the IDToken admin class that is active in this project."""
     id_token_admin_class = oauth2_settings.ID_TOKEN_ADMIN_CLASS
     return id_token_admin_class
 
 
 def get_refresh_token_admin_class():
-    """ Return the RefreshToken admin class that is active in this project. """
+    """Return the RefreshToken admin class that is active in this project."""
     refresh_token_admin_class = oauth2_settings.REFRESH_TOKEN_ADMIN_CLASS
     return refresh_token_admin_class
 
diff --git a/oauth2_provider/views/introspect.py b/oauth2_provider/views/introspect.py
--- a/oauth2_provider/views/introspect.py
+++ b/oauth2_provider/views/introspect.py
@@ -1,8 +1,7 @@
 import calendar
-import json
 
 from django.core.exceptions import ObjectDoesNotExist
-from django.http import HttpResponse
+from django.http import JsonResponse
 from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_exempt
 
@@ -29,9 +28,7 @@ def get_token_response(token_value=None):
                 get_access_token_model().objects.select_related("user", "application").get(token=token_value)
             )
         except ObjectDoesNotExist:
-            return HttpResponse(
-                content=json.dumps({"active": False}), status=401, content_type="application/json"
-            )
+            return JsonResponse({"active": False}, status=401)
         else:
             if token.is_valid():
                 data = {
@@ -43,17 +40,9 @@ def get_token_response(token_value=None):
                     data["client_id"] = token.application.client_id
                 if token.user:
                     data["username"] = token.user.get_username()
-                return HttpResponse(content=json.dumps(data), status=200, content_type="application/json")
+                return JsonResponse(data)
             else:
-                return HttpResponse(
-                    content=json.dumps(
-                        {
-                            "active": False,
-                        }
-                    ),
-                    status=200,
-                    content_type="application/json",
-                )
+                return JsonResponse({"active": False})
 
     def get(self, request, *args, **kwargs):
         """


Test patch: