Skip to content

Commit 6c88b25

Browse files
committed
Fix #340 by defaulting encoding var when request.encoding is None (which is a valid value, as documented: https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.HttpRequest.encoding)
1 parent df5d5a1 commit 6c88b25

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from datetime import timedelta
88

99
from django.utils import timezone
10+
from django.conf import settings
1011
from django.contrib.auth import authenticate
1112
from django.core.exceptions import ObjectDoesNotExist
1213
from oauthlib.oauth2 import RequestValidator
@@ -57,7 +58,7 @@ def _authenticate_basic_auth(self, request):
5758
return False
5859

5960
try:
60-
encoding = request.encoding
61+
encoding = request.encoding or settings.DEFAULT_CHARSET or 'utf-8'
6162
except AttributeError:
6263
encoding = 'utf-8'
6364

oauth2_provider/tests/test_oauth2_validators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ def test_authenticate_basic_auth(self):
5353
self.request.headers = {'HTTP_AUTHORIZATION': 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=\n'}
5454
self.assertTrue(self.validator._authenticate_basic_auth(self.request))
5555

56+
def test_authenticate_basic_auth_default_encoding(self):
57+
self.request.encoding = None
58+
# client_id:client_secret
59+
self.request.headers = {'HTTP_AUTHORIZATION': 'Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=\n'}
60+
self.assertTrue(self.validator._authenticate_basic_auth(self.request))
61+
5662
def test_authenticate_basic_auth_wrong_client_id(self):
5763
self.request.encoding = 'utf-8'
5864
# wrong_id:client_secret

0 commit comments

Comments
 (0)