Skip to content

Commit 1f5aeb6

Browse files
committed
Updated scope gate
1 parent 76a8d85 commit 1f5aeb6

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

apps/dot_ext/tests/test_views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def testing_post_with_share_demographic_scopes(self):
202202
# Loop through test cases in dictionary
203203
cases = VIEW_OAUTH2_SCOPES_TEST_CASES
204204
for case in cases:
205-
print(case)
206205
# Setup request parameters for test case
207206
request_bene_share_demographic_scopes = cases[case][
208207
"request_bene_share_demographic_scopes"

apps/dot_ext/views/authorization.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import waffle
77
from waffle import get_waffle_flag_model
88

9-
from django.conf import settings
109
from django.http.response import HttpResponse, HttpResponseBadRequest
1110
from django.template.response import TemplateResponse
1211
from django.utils.decorators import method_decorator
@@ -23,7 +22,7 @@
2322
from oauth2_provider.models import get_application_model
2423
from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError
2524
from urllib.parse import urlparse, parse_qs
26-
import html
25+
2726
from apps.dot_ext.scopes import CapabilitiesScopes
2827
import apps.logging.request_logger as bb2logging
2928

@@ -121,12 +120,12 @@ def sensitive_info_check(self, request):
121120
def get_template_names(self):
122121
flag = get_waffle_flag_model().get("limit_data_access")
123122
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)):
125124
return ["design_system/new_authorize_v2.html"]
126125
else:
127126
return ["design_system/authorize_v2.html"]
128127
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)):
130129
return ["design_system/new_authorize_v2.html"]
131130
else:
132131
return ["design_system/authorize.html"]
@@ -171,21 +170,16 @@ def form_valid(self, form):
171170
application_available_scopes = CapabilitiesScopes().get_available_scopes(application=application)
172171

173172
# 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])
183175

184176
# Init deleted counts
185177
data_access_grant_delete_cnt = 0
186178
access_token_delete_cnt = 0
187179
refresh_token_delete_cnt = 0
188180

181+
if not scopes:
182+
return self.error_response("No scopes defined", application)
189183
try:
190184
uri, headers, body, status = self.create_authorization_response(
191185
request=self.request, scopes=scopes, credentials=credentials, allow=allow
@@ -362,40 +356,6 @@ def post(self, request, *args, **kwargs):
362356
return super().post(request, args, kwargs)
363357

364358

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-
399359
@method_decorator(csrf_exempt, name="dispatch")
400360
class IntrospectTokenView(DotIntrospectTokenView):
401361

0 commit comments

Comments
 (0)