Skip to content

Commit d719095

Browse files
committed
Add enable_broker_on_wsl flag
1 parent 790bc78 commit d719095

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

msal/application.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .throttled_http_client import ThrottledHttpClient
2222
from .cloudshell import _is_running_in_cloud_shell
2323
from .sku import SKU, __version__
24-
24+
from .oauth2cli.authcode import is_wsl
2525

2626

2727
logger = logging.getLogger(__name__)
@@ -1929,13 +1929,14 @@ def __init__(
19291929
enable_broker_on_windows=None,
19301930
enable_broker_on_mac=None,
19311931
enable_broker_on_linux=None,
1932+
enable_broker_on_wsl=None,
19321933
**kwargs):
19331934
"""Same as :func:`ClientApplication.__init__`,
19341935
except that ``client_credential`` parameter shall remain ``None``.
19351936
19361937
.. note::
19371938
1938-
You may set enable_broker_on_windows and/or enable_broker_on_mac and/or enable_broker_on_linux to True.
1939+
You may set enable_broker_on_windows and/or enable_broker_on_mac and/or enable_broker_on_linux and/or enable_broker_on_wsl to True.
19391940
19401941
**What is a broker, and why use it?**
19411942
@@ -2011,13 +2012,21 @@ def __init__(
20112012
This parameter defaults to None, which means MSAL will not utilize a broker.
20122013
20132014
New in MSAL Python 1.32.0.
2015+
2016+
:param boolean enable_broker_on_wsl:
2017+
This setting is only effective if your app is running on WSL.
2018+
This parameter defaults to None, which means MSAL will not utilize a broker.
2019+
2020+
New in MSAL Python 1.32.0.
20142021
"""
20152022
if client_credential is not None:
20162023
raise ValueError("Public Client should not possess credentials")
2024+
20172025
self._enable_broker = bool(
20182026
enable_broker_on_windows and sys.platform == "win32"
20192027
or enable_broker_on_mac and sys.platform == "darwin"
2020-
or enable_broker_on_linux and sys.platform == "linux")
2028+
or (enable_broker_on_linux or (enable_broker_on_wsl and is_wsl())) and sys.platform == "linux")
2029+
20212030
super(PublicClientApplication, self).__init__(
20222031
client_id, client_credential=None, **kwargs)
20232032

sample/interactive_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#enable_broker_on_windows=True, # Opted in. You will be guided to meet the prerequisites, if your app hasn't already
4949
#enable_broker_on_mac=True, # Opted in. You will be guided to meet the prerequisites, if your app hasn't already
5050
#enable_broker_on_linux=True, # Opted in. You will be guided to meet the prerequisites, if your app hasn't already
51+
#enable_broker_on_wsl=True, # Opted in. You will be guided to meet the prerequisites, if your app hasn't already
5152
token_cache=global_token_cache, # Let this app (re)use an existing token cache.
5253
# If absent, ClientApplication will create its own empty token cache
5354
)

tests/broker-test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
enable_broker_on_mac=True,
4242
enable_broker_on_windows=True,
4343
enable_broker_on_linux=True,
44+
enable_broker_on_wsl=True,
4445
)
4546

4647
def interactive_and_silent(scopes, auth_scheme, data, expected_token_type):

0 commit comments

Comments
 (0)