Skip to content

Commit 2066cb4

Browse files
stiwarisemanticbitsShivam Tiwari
andauthored
BB2-4007: Support POST request for /authorize endpoints (#1364)
Co-authored-by: Shivam Tiwari <[email protected]>
1 parent ba8aa88 commit 2066cb4

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

apps/dot_ext/templates/oauth2_provider/authorize.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,20 @@ <h3 class="block-center-heading">{% trans "Do you approve" %} {{ application.nam
7070
{% endfor %}
7171

7272
<p>{% trans "This application requires following permissions" %}</p>
73-
{{ form.scope|bootstrap5 }}
74-
{{ form.expires_in|bootstrap5 }}
73+
74+
{# Only render the fields if they’re present on the form #}
75+
{% for bf in form.visible_fields %}
76+
{% if bf.name == 'scope' or bf.name == 'expires_in' %}
77+
{% bootstrap_field bf %}
78+
{% endif %}
79+
{% endfor %}
80+
81+
{# If either happens to be a hidden field, include hidden fields too #}
82+
{% for bf in form.hidden_fields %}
83+
{% if bf.name == 'scope' or bf.name == 'expires_in' %}
84+
{{ bf }}
85+
{% endif %}
86+
{% endfor %}
7587

7688
{{ form.non_field_errors }}
7789

apps/dot_ext/views/authorization.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def get_grant_expiration(data_access_type):
5757
class AuthorizationView(DotAuthorizationView):
5858
"""
5959
Override the base authorization view from dot to
60-
use the custom AllowForm.
60+
use the custom AllowForm. Supports both GET and POST
61+
for OAuth params (query string OR form body).
6162
"""
6263
application = None
6364
version = None
@@ -68,6 +69,14 @@ def __init__(self, version=1):
6869
self.version = version
6970
super().__init__()
7071

72+
def _get_param(self, request, key, default=None):
73+
"""Fetch a param from GET first, then POST."""
74+
return request.GET.get(key, request.POST.get(key, default))
75+
76+
def _has_param(self, request, key):
77+
"""True if param exists in either GET or POST."""
78+
return (key in request.GET) or (key in request.POST)
79+
7180
def get_context_data(self, **kwargs):
7281
context = super(AuthorizationView, self).get_context_data(**kwargs)
7382
context['permission_end_date_text'] = self.application.access_end_date_text()
@@ -102,29 +111,38 @@ def dispatch(self, request, *args, **kwargs):
102111
return result
103112

104113
request.session['version'] = self.version
105-
# Store the lang parameter value on the server side with session keyS
106-
lang = request.GET.get('lang', None)
107-
if lang is not None and (lang == 'en' or lang == 'es'):
114+
115+
# Accept lang from GET or POST
116+
lang = self._get_param(request, 'lang')
117+
if lang in ('en', 'es'):
108118
request.session['auth_language'] = lang
119+
109120
return super().dispatch(request, *args, **kwargs)
110121

111122
def sensitive_info_check(self, request):
112-
result = None
113123
for qp in QP_CHECK_LIST:
114-
if request.GET.get(qp, None) is not None:
115-
result = HttpResponseBadRequest("Illegal query parameter [{}] detected".format(qp))
116-
break
117-
return result
118-
119-
def get_template_names(self):
120-
return ["design_system/new_authorize_v2.html"]
124+
if self._has_param(request, qp):
125+
return HttpResponseBadRequest(f"Illegal query parameter [{qp}] detected")
126+
return None
121127

122128
def get_initial(self):
123129
initial_data = super().get_initial()
124-
initial_data["code_challenge"] = self.oauth2_data.get("code_challenge", None)
125-
initial_data["code_challenge_method"] = self.oauth2_data.get("code_challenge_method", None)
130+
# Prefer values parsed by DOT (self.oauth2_data); fall back to incoming request (GET/POST)
131+
initial_data["code_challenge"] = (
132+
self.oauth2_data.get("code_challenge", None)
133+
or self._get_param(self.request, "code_challenge")
134+
)
135+
initial_data["code_challenge_method"] = (
136+
self.oauth2_data.get("code_challenge_method")
137+
or self._get_param(self.request, "code_challenge_method")
138+
)
126139
return initial_data
127140

141+
def post(self, request, *args, **kwargs):
142+
kwargs['code_challenge'] = request.POST.get('code_challenge')
143+
kwargs['code_challenge_method'] = request.POST.get('code_challenge_method')
144+
return super().post(request, *args, **kwargs)
145+
128146
def get(self, request, *args, **kwargs):
129147
kwargs['code_challenge'] = request.GET.get('code_challenge', None)
130148
kwargs['code_challenge_method'] = request.GET.get('code_challenge_method', None)

0 commit comments

Comments
 (0)