Skip to content

Commit 0699b7d

Browse files
Some comments, prevent v3/userinfo from returning successfully if the flag is not enabled for that app
1 parent 499d00a commit 0699b7d

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

apps/accounts/views/oauth2_profile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from collections import OrderedDict
2+
from django.conf import settings
3+
from django.contrib.auth import get_user_model
24
from django.http import JsonResponse
35
from oauth2_provider.contrib.rest_framework import OAuth2Authentication
46
from oauth2_provider.decorators import protected_resource
7+
from oauth2_provider.models import get_access_token_model, get_application_model
58
from rest_framework.decorators import api_view, permission_classes, authentication_classes
9+
from waffle import get_waffle_flag_model
610

711
from apps.authorization.permissions import DataAccessGrantPermission
812
from apps.capabilities.permissions import TokenHasProtectedCapability
@@ -45,6 +49,19 @@ def _get_userinfo(user, version=Versions.NOT_AN_API_VERSION):
4549
@protected_resource() # Django OAuth Toolkit -> resource_owner = AccessToken
4650
def _openidconnect_userinfo(request, version=Versions.NOT_AN_API_VERSION):
4751
# NOTE: The **kwargs are not used anywhere down the callchain, and are being ignored.
52+
# 4250: Handling to ensure this only returns successfully if the flag is enabled for the application
53+
# associated with the user making the call
54+
if version == Versions.V3:
55+
user = get_user_model().objects.get(username=request.resource_owner)
56+
access_token = get_access_token_model().objects.get(user_id=user.id)
57+
application = get_application_model().objects.get(id=access_token.application_id)
58+
application_user = get_user_model().objects.get(id=application.user_id)
59+
flag = get_waffle_flag_model().get('v3_early_adopter')
60+
if flag.id is None or not flag.is_active_for_user(application_user):
61+
return JsonResponse(
62+
{'status_code': 403, 'message': settings.APPLICATION_DOES_NOT_HAVE_V3_ENABLED_YET.format(application.name)},
63+
status=403,
64+
)
4865

4966
return JsonResponse(_get_userinfo(request.resource_owner, version))
5067

@@ -58,6 +75,8 @@ def openidconnect_userinfo_v2(request):
5875

5976

6077
def openidconnect_userinfo_v3(request):
78+
print("openidconnect_userinfo_v3 request: ", request.__dict__)
79+
print("openidconnect_userinfo_v3 user: ", request.user.__dict__)
6180
return _openidconnect_userinfo(request, version=Versions.V3)
6281

6382

apps/dot_ext/views/authorization.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ def _has_param(self, request, key):
150150
def _check_for_required_params(self, request):
151151
missing_params = []
152152
v3 = True if request.path.startswith('/v3/o/authorize') else False
153-
flag = get_waffle_flag_model().get("v3_early_adopter")
154-
req_meta = request.META
155-
url_query = parse_qs(req_meta.get('QUERY_STRING'))
156-
client_id = url_query.get('client_id', [None])
157-
try:
158-
app = get_application_model().objects.get(client_id=client_id[0])
159-
application_user = get_user_model().objects.get(id=app.user_id)
160-
if flag.id is not None and flag.is_active_for_user(application_user):
161-
print("flag is active for this user")
162-
else:
163-
print("flag is not active for this user")
164-
except ObjectDoesNotExist:
165-
print("object not found")
166153

167154
if switch_is_active('require_pkce'):
168155
if not request.GET.get('code_challenge', None):
@@ -177,6 +164,8 @@ def _check_for_required_params(self, request):
177164
error_message = "State parameter should have a minimum of 16 characters"
178165
return JsonResponse({"status_code": 400, "message": error_message}, status=400)
179166

167+
# BB2-4250: This code will not execute if the application is not in the v3_early_adopter flag
168+
# so it will not be modified as part of BB2-4250
180169
if switch_is_active('v3_endpoints') and v3:
181170
if 'scope' not in request.GET:
182171
missing_params.append("scope")
@@ -452,8 +441,8 @@ def dispatch(self, request, uuid, *args, **kwargs):
452441
return result
453442

454443

444+
# @method_decorator(check_v3_endpoint_access, name="dispatch")
455445
@method_decorator(csrf_exempt, name="dispatch")
456-
@method_decorator(check_v3_endpoint_access, name="dispatch")
457446
class TokenView(DotTokenView):
458447

459448
def validate_token_endpoint_request_body(self, request):

apps/fhir/bluebutton/views/search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def filter_parameters(self, request):
186186

187187
query_schema = getattr(self, "QUERY_SCHEMA", {})
188188

189+
# BB2-4250: Does not seem that this code will execute given the new permission class
190+
# so leaving it as is
189191
if waffle.switch_is_active('v3_endpoints'):
190192
query_schema['_tag'] = self.validate_tag()
191193
# _tag if presents, is a string value

0 commit comments

Comments
 (0)