Skip to content

Commit 3716ec4

Browse files
Change remaining HttpResponse to JsonResponse (#989)
* Change remaining HttpResponse to JsonResponse * Add Andrew-Chen-Wang to AUTHORS * Added CHANGELOG entry * Lint
1 parent d90bb34 commit 3716ec4

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Alan Crosswell
1212
Aleksander Vaskevich
1313
Alessandro De Angelis
1414
Allisson Azevedo
15+
Andrew Chen Wang
1516
Anvesh Agarwal
1617
Aristóbulo Meneses
1718
Aryan Iyappan

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
## [unreleased]
1818
* Remove support for Django 3.0
1919
* Add support for Django 3.2
20+
* #989 Change any HttpResponse to JsonResponse if possible
2021

2122
### Added
2223
* #712, #636, #808. Calls to `django.contrib.auth.authenticate()` now pass a `request`

oauth2_provider/models.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -563,56 +563,56 @@ class Meta(AbstractIDToken.Meta):
563563

564564

565565
def get_application_model():
566-
""" Return the Application model that is active in this project. """
566+
"""Return the Application model that is active in this project."""
567567
return apps.get_model(oauth2_settings.APPLICATION_MODEL)
568568

569569

570570
def get_grant_model():
571-
""" Return the Grant model that is active in this project. """
571+
"""Return the Grant model that is active in this project."""
572572
return apps.get_model(oauth2_settings.GRANT_MODEL)
573573

574574

575575
def get_access_token_model():
576-
""" Return the AccessToken model that is active in this project. """
576+
"""Return the AccessToken model that is active in this project."""
577577
return apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
578578

579579

580580
def get_id_token_model():
581-
""" Return the AccessToken model that is active in this project. """
581+
"""Return the AccessToken model that is active in this project."""
582582
return apps.get_model(oauth2_settings.ID_TOKEN_MODEL)
583583

584584

585585
def get_refresh_token_model():
586-
""" Return the RefreshToken model that is active in this project. """
586+
"""Return the RefreshToken model that is active in this project."""
587587
return apps.get_model(oauth2_settings.REFRESH_TOKEN_MODEL)
588588

589589

590590
def get_application_admin_class():
591-
""" Return the Application admin class that is active in this project. """
591+
"""Return the Application admin class that is active in this project."""
592592
application_admin_class = oauth2_settings.APPLICATION_ADMIN_CLASS
593593
return application_admin_class
594594

595595

596596
def get_access_token_admin_class():
597-
""" Return the AccessToken admin class that is active in this project. """
597+
"""Return the AccessToken admin class that is active in this project."""
598598
access_token_admin_class = oauth2_settings.ACCESS_TOKEN_ADMIN_CLASS
599599
return access_token_admin_class
600600

601601

602602
def get_grant_admin_class():
603-
""" Return the Grant admin class that is active in this project. """
603+
"""Return the Grant admin class that is active in this project."""
604604
grant_admin_class = oauth2_settings.GRANT_ADMIN_CLASS
605605
return grant_admin_class
606606

607607

608608
def get_id_token_admin_class():
609-
""" Return the IDToken admin class that is active in this project. """
609+
"""Return the IDToken admin class that is active in this project."""
610610
id_token_admin_class = oauth2_settings.ID_TOKEN_ADMIN_CLASS
611611
return id_token_admin_class
612612

613613

614614
def get_refresh_token_admin_class():
615-
""" Return the RefreshToken admin class that is active in this project. """
615+
"""Return the RefreshToken admin class that is active in this project."""
616616
refresh_token_admin_class = oauth2_settings.REFRESH_TOKEN_ADMIN_CLASS
617617
return refresh_token_admin_class
618618

oauth2_provider/views/introspect.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import calendar
2-
import json
32

43
from django.core.exceptions import ObjectDoesNotExist
5-
from django.http import HttpResponse
4+
from django.http import JsonResponse
65
from django.utils.decorators import method_decorator
76
from django.views.decorators.csrf import csrf_exempt
87

@@ -29,9 +28,7 @@ def get_token_response(token_value=None):
2928
get_access_token_model().objects.select_related("user", "application").get(token=token_value)
3029
)
3130
except ObjectDoesNotExist:
32-
return HttpResponse(
33-
content=json.dumps({"active": False}), status=401, content_type="application/json"
34-
)
31+
return JsonResponse({"active": False}, status=401)
3532
else:
3633
if token.is_valid():
3734
data = {
@@ -43,17 +40,9 @@ def get_token_response(token_value=None):
4340
data["client_id"] = token.application.client_id
4441
if token.user:
4542
data["username"] = token.user.get_username()
46-
return HttpResponse(content=json.dumps(data), status=200, content_type="application/json")
43+
return JsonResponse(data)
4744
else:
48-
return HttpResponse(
49-
content=json.dumps(
50-
{
51-
"active": False,
52-
}
53-
),
54-
status=200,
55-
content_type="application/json",
56-
)
45+
return JsonResponse({"active": False})
5746

5847
def get(self, request, *args, **kwargs):
5948
"""

0 commit comments

Comments
 (0)