|
6 | 6 | import waffle |
7 | 7 | from waffle import get_waffle_flag_model |
8 | 8 |
|
9 | | -from django.conf import settings |
10 | 9 | from django.http.response import HttpResponse, HttpResponseBadRequest |
11 | 10 | from django.template.response import TemplateResponse |
12 | 11 | from django.utils.decorators import method_decorator |
|
23 | 22 | from oauth2_provider.models import get_application_model |
24 | 23 | from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError |
25 | 24 | from urllib.parse import urlparse, parse_qs |
26 | | -import html |
| 25 | + |
27 | 26 | from apps.dot_ext.scopes import CapabilitiesScopes |
28 | 27 | import apps.logging.request_logger as bb2logging |
29 | 28 |
|
@@ -121,12 +120,12 @@ def sensitive_info_check(self, request): |
121 | 120 | def get_template_names(self): |
122 | 121 | flag = get_waffle_flag_model().get("limit_data_access") |
123 | 122 | if waffle.switch_is_active('require-scopes'): |
124 | | - if flag.rollout or (flag.id is not None and self.application and flag.is_active_for_user(self.application.user)): |
| 123 | + if flag.rollout or (flag.id is not None and flag.is_active_for_user(self.application.user)): |
125 | 124 | return ["design_system/new_authorize_v2.html"] |
126 | 125 | else: |
127 | 126 | return ["design_system/authorize_v2.html"] |
128 | 127 | else: |
129 | | - if flag.rollout or (flag.id is not None and self.user and flag.is_active_for_user(self.user)): |
| 128 | + if flag.rollout or (flag.id is not None and flag.is_active_for_user(self.user)): |
130 | 129 | return ["design_system/new_authorize_v2.html"] |
131 | 130 | else: |
132 | 131 | return ["design_system/authorize.html"] |
@@ -171,21 +170,16 @@ def form_valid(self, form): |
171 | 170 | application_available_scopes = CapabilitiesScopes().get_available_scopes(application=application) |
172 | 171 |
|
173 | 172 | # Set scopes to those available to application and beneficiary demographic info choices |
174 | | - if share_demographic_scopes == "True": |
175 | | - scopes = ' '.join( |
176 | | - [s for s in scopes.split(" ") if s in application_available_scopes] |
177 | | - ) |
178 | | - else: |
179 | | - scopes = ' '.join( |
180 | | - [s for s in scopes.split(" ") |
181 | | - if s in application_available_scopes and s not in settings.BENE_PERSONAL_INFO_SCOPES] |
182 | | - ) |
| 173 | + scopes = ' '.join([s for s in scopes.split(" ") |
| 174 | + if s in application_available_scopes]) |
183 | 175 |
|
184 | 176 | # Init deleted counts |
185 | 177 | data_access_grant_delete_cnt = 0 |
186 | 178 | access_token_delete_cnt = 0 |
187 | 179 | refresh_token_delete_cnt = 0 |
188 | 180 |
|
| 181 | + if not scopes: |
| 182 | + return self.error_response("No scopes defined", application) |
189 | 183 | try: |
190 | 184 | uri, headers, body, status = self.create_authorization_response( |
191 | 185 | request=self.request, scopes=scopes, credentials=credentials, allow=allow |
@@ -362,40 +356,6 @@ def post(self, request, *args, **kwargs): |
362 | 356 | return super().post(request, args, kwargs) |
363 | 357 |
|
364 | 358 |
|
365 | | -@method_decorator(csrf_exempt, name="dispatch") |
366 | | -class RevokeView(DotRevokeTokenView): |
367 | | - |
368 | | - @method_decorator(sensitive_post_parameters("password")) |
369 | | - def post(self, request, *args, **kwargs): |
370 | | - at_model = get_access_token_model() |
371 | | - try: |
372 | | - app = validate_app_is_active(request) |
373 | | - except (InvalidClientError, InvalidGrantError) as error: |
374 | | - return json_response_from_oauth2_error(error) |
375 | | - |
376 | | - tkn = request.POST.get('token') |
377 | | - if tkn is not None: |
378 | | - escaped_tkn = html.escape(tkn) |
379 | | - else: |
380 | | - escaped_tkn = "" |
381 | | - |
382 | | - try: |
383 | | - token = at_model.objects.get(token=tkn) |
384 | | - except at_model.DoesNotExist: |
385 | | - log.debug(f"Token {escaped_tkn} was not found.") |
386 | | - |
387 | | - try: |
388 | | - dag = DataAccessGrant.objects.get( |
389 | | - beneficiary=token.user, |
390 | | - application=app |
391 | | - ) |
392 | | - dag.delete() |
393 | | - except Exception: |
394 | | - log.debug(f"DAG lookup failed for token {escaped_tkn}.") |
395 | | - |
396 | | - return super().post(request, args, kwargs) |
397 | | - |
398 | | - |
399 | 359 | @method_decorator(csrf_exempt, name="dispatch") |
400 | 360 | class IntrospectTokenView(DotIntrospectTokenView): |
401 | 361 |
|
|
0 commit comments