|
7 | 7 | from django.conf import settings |
8 | 8 | from django.contrib.auth import get_user_model |
9 | 9 | from django.contrib.auth.views import redirect_to_login |
10 | | -from django.http import JsonResponse |
| 10 | +from django.http import HttpResponseForbidden, JsonResponse |
11 | 11 | from django.http.response import HttpResponse, HttpResponseBadRequest |
12 | 12 | from django.template.response import TemplateResponse |
13 | 13 | from django.core.exceptions import ObjectDoesNotExist, PermissionDenied |
@@ -154,7 +154,11 @@ def dispatch(self, request, *args, **kwargs): |
154 | 154 | version = get_api_version_number_from_url(path_info) |
155 | 155 | # If it is not version 3, we don't need to check anything, just return |
156 | 156 | if version == Versions.V3: |
157 | | - self.validate_v3_authorization_request() |
| 157 | + try: |
| 158 | + self.validate_v3_authorization_request() |
| 159 | + except AccessDeniedTokenCustomError as e: |
| 160 | + return HttpResponseForbidden(e) |
| 161 | + |
158 | 162 | # TODO: Should the client_id match a valid application here before continuing, instead of after matching to FHIR_ID? |
159 | 163 | if not kwargs.get('is_subclass_approvalview', False): |
160 | 164 | # Create new authorization flow trace UUID in session and AuthFlowUuid instance, if subclass is not ApprovalView |
@@ -258,7 +262,7 @@ def validate_v3_authorization_request(self): |
258 | 262 | ) |
259 | 263 | except ObjectDoesNotExist: |
260 | 264 | raise AccessDeniedTokenCustomError( |
261 | | - description='You do not have permission to perform this action.' |
| 265 | + description='Unable to verify permission.' |
262 | 266 | ) |
263 | 267 |
|
264 | 268 | def form_valid(self, form): |
@@ -466,7 +470,7 @@ def validate_v3_token_call(self, request) -> None: |
466 | 470 | ) |
467 | 471 | except ObjectDoesNotExist: |
468 | 472 | return JsonResponse( |
469 | | - {'status_code': 403, 'message': 'You do not have permission to perform this action.'}, |
| 473 | + {'status_code': 403, 'message': 'Unable to verify permission.'}, |
470 | 474 | status=403, |
471 | 475 | ) |
472 | 476 |
|
|
0 commit comments