Skip to content

Commit 7174bdf

Browse files
authored
BB2-3796: Allow POST in auth requests (#1312)
* Added authorization post support and state requriement for posting * Cleanup
1 parent 66dd322 commit 7174bdf

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

apps/capabilities/management/commands/create_blue_button_scopes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,3 @@ def handle(self, *args, **options):
307307
create_coverage_read_search_capability(g, fhir_prefix)
308308
create_launch_capability(g, fhir_prefix)
309309
create_openid_capability(g)
310-
311-
call_command('loaddata', 'internal_application_labels.json')
312-

apps/dot_ext/views/authorization.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def form_valid(self, form):
238238
return self.redirect(self.success_url, application)
239239

240240

241+
@method_decorator(csrf_exempt, name="dispatch")
241242
class ApprovalView(AuthorizationView):
242243
"""
243244
Override the base authorization view from dot to
@@ -252,6 +253,9 @@ def __init__(self, version=1):
252253
super().__init__()
253254

254255
def dispatch(self, request, uuid, *args, **kwargs):
256+
if request.method == "POST" and request.POST.get("state") is None:
257+
return JsonResponse({"status_code": 401, "message": "State required for POST requests."}, status=401)
258+
255259
# Get auth_uuid to set again after super() return. It gets cleared out otherwise.
256260
auth_flow_dict = get_session_auth_flow_trace(request)
257261
try:
@@ -276,7 +280,7 @@ def dispatch(self, request, uuid, *args, **kwargs):
276280
if hasattr(result, "headers") \
277281
and "Location" in result.headers \
278282
and "invalid_scope" in result.headers['Location']:
279-
return JsonResponse({"status_code": 400, "message": "Invalid scopes."})
283+
return JsonResponse({"status_code": 400, "message": "Invalid scopes."}, status=400)
280284

281285
if hasattr(self, 'oauth2_data'):
282286
application = self.oauth2_data.get('application', None)

apps/mymedicare_cb/tests/test_callback_slsx.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def test_authorize_uuid(self):
174174
"client_id": "bad",
175175
"redirect_uri": "http://test.com",
176176
"response_type": "code",
177+
"state": "1234567890",
177178
},
178179
)
179180
self.assertEqual(status.HTTP_302_FOUND, response.status_code)
@@ -184,6 +185,7 @@ def test_authorize_uuid(self):
184185
"scope": ["capability-a"],
185186
"expires_in": 86400,
186187
"allow": True,
188+
"state": "1234567890",
187189
}
188190
response = self.client.post(auth_uri, data=payload)
189191
self.assertEqual(status.HTTP_302_FOUND, response.status_code)
@@ -196,9 +198,20 @@ def test_authorize_uuid(self):
196198
"client_id": application.client_id,
197199
"redirect_uri": "http://test.com",
198200
"response_type": "code",
201+
"state": "1234567890",
199202
},
200203
)
201204
self.assertEqual(status.HTTP_302_FOUND, response.status_code)
205+
# Test without state
206+
response = self.client.post(
207+
auth_uri,
208+
data={
209+
"client_id": application.client_id,
210+
"redirect_uri": "http://test.com",
211+
"response_type": "code",
212+
},
213+
)
214+
self.assertEqual(status.HTTP_401_UNAUTHORIZED, response.status_code)
202215

203216
def test_callback_url_success(self):
204217
# create a state

0 commit comments

Comments
 (0)