Skip to content

Commit a3c085e

Browse files
authored
pass PKCE fields to AuthorizationView form (#896)
* add tests for issue of PKCE authorization code GET request * pass PKCE fields to AuthorizationView form Pass code_challenge and code_challenge_method from query string to AuthorizationView form in get(). Without this, it was impossible to use authorization code grant flow with GET, because code_challenge and code_challenge_method data were never passed to form, so they weren't in form.cleaned_data, which causes creating Grant with always empty code_challenge and code_challenge_method. This issue was quite hard bug to discover because there are already few tests for authorization code flow pkce, however, they weren't checking form rendering in GET request, but only response.status_code, I have added asserts for these 2 values, please look at the changes in test_public_pkce_plain_authorize_get and test_public_pkce_S256_authorize_get tests in test_authorization_code.py.
1 parent 6f08e3b commit a3c085e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ Rodney Richardson
3030
Silvano Cerza
3131
Stéphane Raimbault
3232
Jun Zhou
33-
David Smith
33+
David Smith
34+
Łukasz Skarżyński

oauth2_provider/views/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def get(self, request, *args, **kwargs):
156156
kwargs["redirect_uri"] = credentials["redirect_uri"]
157157
kwargs["response_type"] = credentials["response_type"]
158158
kwargs["state"] = credentials["state"]
159+
if "code_challenge" in credentials:
160+
kwargs["code_challenge"] = credentials["code_challenge"]
161+
if "code_challenge_method" in credentials:
162+
kwargs["code_challenge_method"] = credentials["code_challenge_method"]
159163

160164
self.oauth2_data = kwargs
161165
# following two loc are here only because of https://code.djangoproject.com/ticket/17795

tests/test_authorization_code.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ def test_public_pkce_S256_authorize_get(self):
10121012
"""
10131013
Request an access token using client_type: public
10141014
and PKCE enabled. Tests if the authorize get is successfull
1015-
for the S256 algorithm
1015+
for the S256 algorithm and form data are properly passed.
10161016
"""
10171017
self.client.login(username="test_user", password="123456")
10181018

@@ -1033,14 +1033,15 @@ def test_public_pkce_S256_authorize_get(self):
10331033
}
10341034

10351035
response = self.client.get(reverse("oauth2_provider:authorize"), data=query_data)
1036-
self.assertEqual(response.status_code, 200)
1036+
self.assertContains(response, 'value="S256"', count=1, status_code=200)
1037+
self.assertContains(response, 'value="{0}"'.format(code_challenge), count=1, status_code=200)
10371038
oauth2_settings.PKCE_REQUIRED = False
10381039

10391040
def test_public_pkce_plain_authorize_get(self):
10401041
"""
10411042
Request an access token using client_type: public
10421043
and PKCE enabled. Tests if the authorize get is successfull
1043-
for the plain algorithm
1044+
for the plain algorithm and form data are properly passed.
10441045
"""
10451046
self.client.login(username="test_user", password="123456")
10461047

@@ -1061,7 +1062,8 @@ def test_public_pkce_plain_authorize_get(self):
10611062
}
10621063

10631064
response = self.client.get(reverse("oauth2_provider:authorize"), data=query_data)
1064-
self.assertEqual(response.status_code, 200)
1065+
self.assertContains(response, 'value="plain"', count=1, status_code=200)
1066+
self.assertContains(response, 'value="{0}"'.format(code_challenge), count=1, status_code=200)
10651067
oauth2_settings.PKCE_REQUIRED = False
10661068

10671069
def test_public_pkce_S256(self):

0 commit comments

Comments
 (0)