From c4e765efbf116beed4933db2536bbae7ea9f27c4 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Fri, 22 Jun 2018 05:05:05 +0430 Subject: [PATCH 1/2] Ignoring requests containing list instead of dict If a request's body is a json list instead of a json object django-oauth-toolkit raises and exception. It breaks bulk requests for drf for example. This commit fixes it. --- oauth2_provider/oauth2_backends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth2_provider/oauth2_backends.py b/oauth2_provider/oauth2_backends.py index 62791098c..9609321d4 100644 --- a/oauth2_provider/oauth2_backends.py +++ b/oauth2_provider/oauth2_backends.py @@ -180,7 +180,7 @@ def extract_body(self, request): """ try: body = json.loads(request.body.decode("utf-8")).items() - except ValueError: + except AttributeError, ValueError: body = "" return body From a44f536404dd20b4097c11b33efcc8d126354c42 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Fri, 22 Jun 2018 05:09:06 +0430 Subject: [PATCH 2/2] Fixed syntax error --- oauth2_provider/oauth2_backends.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oauth2_provider/oauth2_backends.py b/oauth2_provider/oauth2_backends.py index 9609321d4..8a1c239b5 100644 --- a/oauth2_provider/oauth2_backends.py +++ b/oauth2_provider/oauth2_backends.py @@ -180,7 +180,9 @@ def extract_body(self, request): """ try: body = json.loads(request.body.decode("utf-8")).items() - except AttributeError, ValueError: + except AttributeError: + body = "" + except ValueError: body = "" return body