From 6243b7076f3394f7fcd13fac90a5655b6b204efc Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Fri, 18 Jun 2021 19:59:43 -0400 Subject: [PATCH 1/3] Change remaining HttpResponse to JsonResponse * Add Andrew-Chen-Wang to AUTHORS --- AUTHORS | 1 + oauth2_provider/views/introspect.py | 19 ++++--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index 50589287a..8cb1b7a05 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,6 +12,7 @@ Alan Crosswell Aleksander Vaskevich Alessandro De Angelis Allisson Azevedo +Andrew Chen Wang Anvesh Agarwal Aristóbulo Meneses Aryan Iyappan diff --git a/oauth2_provider/views/introspect.py b/oauth2_provider/views/introspect.py index afb8ac627..08b4b4222 100644 --- 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): """ From 4bb0be6cb5fdbef0196fdd01c581117e72b3a988 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Fri, 2 Jul 2021 02:02:45 -0400 Subject: [PATCH 2/3] Added CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b2deb05d..45d63276f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] * Remove support for Django 3.0 * Add support for Django 3.2 +* #989 Change any HttpResponse to JsonResponse if possible ### Added * #712, #636, #808. Calls to `django.contrib.auth.authenticate()` now pass a `request` From 5af4efc2c4753cb618b1ef4c83ed53d009a10b30 Mon Sep 17 00:00:00 2001 From: Andrew Chen Wang <60190294+Andrew-Chen-Wang@users.noreply.github.com> Date: Fri, 2 Jul 2021 04:16:53 -0400 Subject: [PATCH 3/3] Lint --- oauth2_provider/models.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/oauth2_provider/models.py b/oauth2_provider/models.py index aa10eca16..526173281 100644 --- 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