Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,23 +999,29 @@ def _create_identity_instance(cli_ctx, authority, tenant_id=None, client_id=None
"""Lazily import and create Identity instance to avoid unnecessary imports."""
from .auth.identity import Identity
from .util import should_encrypt_token_cache
from .telemetry import set_broker_info

encrypt = should_encrypt_token_cache(cli_ctx)

# EXPERIMENTAL: Use core.use_msal_http_cache=False to turn off MSAL HTTP cache.
use_msal_http_cache = cli_ctx.config.getboolean('core', 'use_msal_http_cache', fallback=True)

# On Windows, use core.enable_broker_on_windows=false to disable broker (WAM) for authentication.
enable_broker_on_windows = cli_ctx.config.getboolean('core', 'enable_broker_on_windows', fallback=True)
from .telemetry import set_broker_info
set_broker_info(enable_broker_on_windows)

# On WSL, use core.enable_broker_on_wsl=true to use broker (WAM)
enable_broker_on_wsl = cli_ctx.config.getboolean('core', 'enable_broker_on_wsl', fallback=False)
set_broker_info(enable_broker_on_wsl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_broker_info(enable_broker_on_windows, enable_broker_on_wsl) expects both enable_broker_on_windows and enable_broker_on_wsl, but it’s currently called with a single positional argument. It might be clearer and safer to pass both values in a single call (or use keyword arguments) to avoid misconfiguration.


# PREVIEW: In Azure Stack environment, use core.instance_discovery=false to disable MSAL's instance discovery.
instance_discovery = cli_ctx.config.getboolean('core', 'instance_discovery', True)

return Identity(authority, tenant_id=tenant_id, client_id=client_id,
encrypt=encrypt,
use_msal_http_cache=use_msal_http_cache,
enable_broker_on_windows=enable_broker_on_windows,
enable_broker_on_wsl=enable_broker_on_wsl,
instance_discovery=instance_discovery)


Expand Down
9 changes: 7 additions & 2 deletions src/azure-cli-core/azure/cli/core/auth/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Identity: # pylint: disable=too-many-instance-attributes
_service_principal_store_instance = None

def __init__(self, authority, tenant_id=None, client_id=None, encrypt=False, use_msal_http_cache=True,
enable_broker_on_windows=None, instance_discovery=None):
enable_broker_on_windows=None, enable_broker_on_wsl=None,
instance_discovery=None):
"""
:param authority: Authentication authority endpoint. For example,
- AAD: https://login.microsoftonline.com
Expand All @@ -74,6 +75,7 @@ def __init__(self, authority, tenant_id=None, client_id=None, encrypt=False, use
self._encrypt = encrypt
self._use_msal_http_cache = use_msal_http_cache
self._enable_broker_on_windows = enable_broker_on_windows
self._enable_broker_on_wsl = enable_broker_on_wsl
self._instance_discovery = instance_discovery

# Build the authority in MSAL style
Expand Down Expand Up @@ -112,7 +114,10 @@ def _msal_app_kwargs(self):
def _msal_public_app_kwargs(self):
"""kwargs for creating PublicClientApplication."""
# enable_broker_on_windows can only be used on PublicClientApplication.
return {**self._msal_app_kwargs, "enable_broker_on_windows": self._enable_broker_on_windows}
return {**self._msal_app_kwargs,
"enable_broker_on_windows": self._enable_broker_on_windows,
"enable_broker_on_wsl": self._enable_broker_on_wsl
}

@property
def _msal_app(self):
Expand Down
5 changes: 4 additions & 1 deletion src/azure-cli-core/azure/cli/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self, correlation_id=None, application=None):
self.user_agent = None
# authentication-related
self.enable_broker_on_windows = None
self.enable_broker_on_wsl = None
self.msal_telemetry = None
self.login_experience_v2 = None

Expand Down Expand Up @@ -232,6 +233,7 @@ def _get_azure_cli_properties(self):
set_custom_properties(result, 'SecretNames', ','.join(self.secret_names or []))
# authentication-related
set_custom_properties(result, 'EnableBrokerOnWindows', str(self.enable_broker_on_windows))
set_custom_properties(result, 'EnableBrokerOnWsl', str(self.enable_broker_on_wsl))
set_custom_properties(result, 'MsalTelemetry', self.msal_telemetry)
set_custom_properties(result, 'LoginExperienceV2', str(self.login_experience_v2))

Expand Down Expand Up @@ -471,9 +473,10 @@ def set_region_identified(region_input, region_identified):


@decorators.suppress_all_exceptions()
def set_broker_info(enable_broker_on_windows):
def set_broker_info(enable_broker_on_windows, enable_broker_on_wsl):
# Log the value of `enable_broker_on_windows`
_session.enable_broker_on_windows = enable_broker_on_windows
_session.enable_broker_on_wsl = enable_broker_on_wsl


@decorators.suppress_all_exceptions()
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ psutil==6.1.0
pycomposefile==0.0.32
PyGithub==1.55
PyJWT==2.4.0
pymsalruntime==0.18.1
PyNaCl==1.5.0
pyOpenSSL==25.0.0
python-dateutil==2.8.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ psutil==6.1.0
pycomposefile==0.0.32
PyGithub==1.55
PyJWT==2.4.0
pymsalruntime==0.16.2
pymsalruntime==0.18.1
PyNaCl==1.5.0
pyOpenSSL==25.0.0
python-dateutil==2.8.0
Expand Down
Loading