Skip to content

Commit ba1e232

Browse files
committed
Merge branch 'honestbleeps-redirect-fix'
2 parents 78efc3a + bbe01b0 commit ba1e232

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

oauth2_provider/tests/test_authorization_code.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,27 @@ def test_code_post_auth_redirection_uri_with_querystring(self):
423423
self.assertIn("http://example.com?foo=bar", response['Location'])
424424
self.assertIn("code=", response['Location'])
425425

426+
def test_code_post_auth_failing_redirection_uri_with_querystring(self):
427+
"""
428+
Test that in case of error the querystring of the redirection uri is preserved
429+
430+
See https://github.com/evonove/django-oauth-toolkit/issues/238
431+
"""
432+
self.client.login(username="test_user", password="123456")
433+
434+
form_data = {
435+
'client_id': self.application.client_id,
436+
'state': 'random_state_string',
437+
'scope': 'read write',
438+
'redirect_uri': 'http://example.com?foo=bar',
439+
'response_type': 'code',
440+
'allow': False,
441+
}
442+
443+
response = self.client.post(reverse('oauth2_provider:authorize'), data=form_data)
444+
self.assertEqual(response.status_code, 302)
445+
self.assertEqual("http://example.com?foo=bar&error=access_denied", response['Location'])
446+
426447
def test_code_post_auth_fails_when_redirect_uri_path_is_invalid(self):
427448
"""
428449
Tests that a redirection uri is matched using scheme + netloc + path

oauth2_provider/views/mixins.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ def error_response(self, error, **kwargs):
155155
:param error: :attr:`OAuthToolkitError`
156156
"""
157157
oauthlib_error = error.oauthlib_error
158+
159+
redirect_uri = oauthlib_error.redirect_uri or ""
160+
separator = '&' if '?' in redirect_uri else '?'
161+
158162
error_response = {
159163
'error': oauthlib_error,
160-
'url': "{0}?{1}".format(oauthlib_error.redirect_uri, oauthlib_error.urlencoded)
164+
'url': "{0}{1}{2}".format(oauthlib_error.redirect_uri, separator, oauthlib_error.urlencoded)
161165
}
162166
error_response.update(kwargs)
163167

0 commit comments

Comments
 (0)