@@ -91,6 +91,8 @@ class AuthorizationView(DotAuthorizationView):
9191 # TODO: rename this so that it isn't the same as self.version (works but confusing)
9292 # this needs to be here for urls.py as_view(version) calls, but don't use it
9393 version = 0
94+ # Variable to help reduce the amount of times validate_v3_authorization_request is called
95+ validate_v3_call = True
9496 form_class = SimpleAllowForm
9597 login_url = "/mymedicare/login"
9698
@@ -149,6 +151,11 @@ def dispatch(self, request, *args, **kwargs):
149151 initially create an AuthFlowUuid object for authorization
150152 flow tracing in logs.
151153 """
154+ path_info = self .request .__dict__ .get ('path_info' )
155+ version = get_api_version_number_from_url (path_info )
156+ # If it is not version 3, we don't need to check anything, just return
157+ if version == Versions .V3 and self .validate_v3_call :
158+ self .validate_v3_authorization_request ()
152159 # TODO: Should the client_id match a valid application here before continuing, instead of after matching to FHIR_ID?
153160 if not kwargs .get ('is_subclass_approvalview' , False ):
154161 # Create new authorization flow trace UUID in session and AuthFlowUuid instance, if subclass is not ApprovalView
@@ -241,7 +248,11 @@ def validate_v3_authorization_request(self):
241248 try :
242249 application = get_application_model ().objects .get (client_id = client_id [0 ])
243250 application_user = get_user_model ().objects .get (id = application .user_id )
244- if flag .id is not None and flag .is_active_for_user (application_user ):
251+
252+ if flag .id is None or flag .is_active_for_user (application_user ):
253+ # Update the class variable to ensure subsequent calls to dispatch don't call this function
254+ # more times than is needed
255+ self .validate_v3_call = False
245256 return
246257 else :
247258 raise AccessDeniedTokenCustomError (
@@ -292,11 +303,6 @@ def form_valid(self, form):
292303 refresh_token_delete_cnt = 0
293304
294305 try :
295- path_info = self .request .__dict__ .get ('path_info' )
296- version = get_api_version_number_from_url (path_info )
297- # If it is not version 3, we don't need to check anything, just return
298- if version == Versions .V3 :
299- self .validate_v3_authorization_request ()
300306
301307 if not scopes :
302308 # Since the create_authorization_response will re-inject scopes even when none are
@@ -456,7 +462,7 @@ def validate_v3_token_call(self, request) -> None:
456462 application = get_application_model ().objects .get (id = refresh_token .application_id )
457463 application_user = get_user_model ().objects .get (id = application .user_id )
458464
459- if flag .id is not None and flag .is_active_for_user (application_user ):
465+ if flag .id is None or flag .is_active_for_user (application_user ):
460466 return
461467 else :
462468 raise PermissionDenied (
0 commit comments