Skip to content

Commit 6f97011

Browse files
committed
fixes for oauthlib 1.0
1 parent 764b83c commit 6f97011

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ def _authenticate_basic_auth(self, request):
5555
if not auth_string:
5656
return False
5757

58-
encoding = request.encoding or 'utf-8'
58+
try:
59+
encoding = request.encoding
60+
except AttributeError:
61+
encoding = 'utf-8'
5962

6063
try:
6164
b64_decoded = base64.b64decode(auth_string)
@@ -91,10 +94,10 @@ def _authenticate_request_body(self, request):
9194
directly utilize the HTTP Basic authentication scheme. See rfc:`2.3.1` for more details.
9295
"""
9396
# TODO: check if oauthlib has already unquoted client_id and client_secret
94-
client_id = request.client_id
95-
client_secret = request.client_secret
96-
97-
if not client_id or not client_secret:
97+
try:
98+
client_id = request.client_id
99+
client_secret = request.client_secret
100+
except AttributeError:
98101
return False
99102

100103
if self._load_application(client_id, request) is None:
@@ -143,8 +146,12 @@ def client_authentication_required(self, request, *args, **kwargs):
143146
if self._extract_basic_auth(request):
144147
return True
145148

146-
if request.client_id and request.client_secret:
147-
return True
149+
try:
150+
if request.client_id and request.client_secret:
151+
return True
152+
except AttributeError:
153+
log.debug("Client id or client secret not provided, proceed evaluating if authentication is required...")
154+
pass
148155

149156
self._load_application(request.client_id, request)
150157
if request.client:

oauth2_provider/tests/test_authorization_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def test_pre_auth_wrong_response_type(self):
261261

262262
response = self.client.get(url)
263263
self.assertEqual(response.status_code, 302)
264-
self.assertIn("error=unauthorized_client", response['Location'])
264+
self.assertIn("error=unsupported_response_type", response['Location'])
265265

266266
def test_code_post_auth_allow(self):
267267
"""

0 commit comments

Comments
 (0)