Skip to content

Skip unnecessary and repetitive region detection #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _get_regional_authority(self, central_authority):
validate_authority=False) # The central_authority has already been validated
return None

def _build_client(self, client_credential, authority):
def _build_client(self, client_credential, authority, skip_regional_client=False):
client_assertion = None
client_assertion_type = None
default_headers = {
Expand Down Expand Up @@ -417,7 +417,8 @@ def _build_client(self, client_credential, authority):
on_updating_rt=self.token_cache.update_rt)

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

response = None # A distinguishable value to mean cache is empty
if not matches: # Then exit early to avoid expensive operations
return response
client, _ = self._build_client(
# Potentially expensive if building regional client
self.client_credential, authority, skip_regional_client=True)
telemetry_context = self._build_telemetry_context(
self.ACQUIRE_TOKEN_SILENT_ID,
correlation_id=correlation_id, refresh_reason=refresh_reason)
Expand Down