Skip to content

Commit 768e4ff

Browse files
committed
Merge branch '244', oauthlib compatibility
2 parents b92bfc6 + 166308f commit 768e4ff

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
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
"""

oauth2_provider/tests/test_token_revocation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ def test_revoke_access_token(self):
6060
self.assertEqual(response.content, b'')
6161
self.assertFalse(AccessToken.objects.filter(id=tok.id).exists())
6262

63+
def test_revoke_access_token_public(self):
64+
public_app = Application(
65+
name="Test Application",
66+
redirect_uris="http://localhost http://example.com http://example.it",
67+
user=self.dev_user,
68+
client_type=Application.CLIENT_PUBLIC,
69+
authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
70+
)
71+
public_app.save()
72+
73+
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
74+
application=public_app,
75+
expires=timezone.now() + datetime.timedelta(days=1),
76+
scope='read write')
77+
78+
query_string = urlencode({
79+
'client_id': public_app.client_id,
80+
'token': tok.token,
81+
})
82+
83+
url = "{url}?{qs}".format(url=reverse('oauth2_provider:revoke-token'), qs=query_string)
84+
response = self.client.post(url)
85+
self.assertEqual(response.status_code, 200)
86+
6387
def test_revoke_access_token_with_hint(self):
6488
"""
6589

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Sphinx==1.3.1
22
South==1.0
3-
oauthlib>=0.6.2
3+
oauthlib==1.0.1
44
django-braces==1.4.0
55
six

0 commit comments

Comments
 (0)