Skip to content

Commit f607de9

Browse files
committed
Skip unnecessary and repetitive region detection
1 parent babe142 commit f607de9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

msal/application.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def _get_regional_authority(self, central_authority):
358358
validate_authority=False) # The central_authority has already been validated
359359
return None
360360

361-
def _build_client(self, client_credential, authority):
361+
def _build_client(self, client_credential, authority, skip_regional_client=False):
362362
client_assertion = None
363363
client_assertion_type = None
364364
default_headers = {
@@ -417,7 +417,8 @@ def _build_client(self, client_credential, authority):
417417
on_updating_rt=self.token_cache.update_rt)
418418

419419
regional_client = None
420-
if client_credential: # Currently regional endpoint only serves some CCA flows
420+
if (client_credential # Currently regional endpoint only serves some CCA flows
421+
and not skip_regional_client):
421422
regional_authority = self._get_regional_authority(authority)
422423
if regional_authority:
423424
regional_configuration = {
@@ -1076,9 +1077,13 @@ def _acquire_token_silent_by_finding_specific_refresh_token(
10761077
# target=scopes, # AAD RTs are scope-independent
10771078
query=query)
10781079
logger.debug("Found %d RTs matching %s", len(matches), query)
1079-
client, _ = self._build_client(self.client_credential, authority)
10801080

10811081
response = None # A distinguishable value to mean cache is empty
1082+
if not matches: # Then exit early to avoid expensive operations
1083+
return response
1084+
client, _ = self._build_client(
1085+
# Potentially expensive if building regional client
1086+
self.client_credential, authority, skip_regional_client=True)
10821087
telemetry_context = self._build_telemetry_context(
10831088
self.ACQUIRE_TOKEN_SILENT_ID,
10841089
correlation_id=correlation_id, refresh_reason=refresh_reason)

0 commit comments

Comments
 (0)