2121from .throttled_http_client import ThrottledHttpClient
2222from .cloudshell import _is_running_in_cloud_shell
2323from .sku import SKU , __version__
24-
24+ from . oauth2cli . authcode import is_wsl
2525
2626
2727logger = logging .getLogger (__name__ )
@@ -164,6 +164,8 @@ def _preferred_browser():
164164 pass # We may still proceed
165165 return None
166166
167+ def _is_ssh_cert_or_pop_request (token_type , auth_scheme ) -> bool :
168+ return token_type == "ssh-cert" or token_type == "pop" or isinstance (auth_scheme , msal .auth_scheme .PopAuthScheme )
167169
168170class _ClientWithCcsRoutingInfo (Client ):
169171
@@ -710,7 +712,7 @@ def _decide_broker(self, allow_broker, enable_pii_log):
710712
711713 def is_pop_supported (self ):
712714 """Returns True if this client supports Proof-of-Possession Access Token."""
713- return self ._enable_broker
715+ return self ._enable_broker and sys . platform in ( "win32" , "darwin" )
714716
715717 def _decorate_scope (
716718 self , scopes ,
@@ -1582,10 +1584,12 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
15821584 raise ValueError ("auth_scheme is not supported in Cloud Shell" )
15831585 return self ._acquire_token_by_cloud_shell (scopes , data = data )
15841586
1587+ is_ssh_cert_or_pop_request = _is_ssh_cert_or_pop_request (data .get ("token_type" ), auth_scheme )
1588+
15851589 if self ._enable_broker and account and account .get ("account_source" ) in (
15861590 _GRANT_TYPE_BROKER , # Broker successfully established this account previously.
15871591 None , # Unknown data from older MSAL. Broker might still work.
1588- ):
1592+ ) and ( sys . platform in ( "win32" , "darwin" ) or not is_ssh_cert_or_pop_request ) :
15891593 from .broker import _acquire_token_silently
15901594 response = _acquire_token_silently (
15911595 "https://{}/{}" .format (self .authority .instance , self .authority .tenant ),
@@ -1832,7 +1836,7 @@ def acquire_token_by_username_password(
18321836 """
18331837 claims = _merge_claims_challenge_and_capabilities (
18341838 self ._client_capabilities , claims_challenge )
1835- if self ._enable_broker :
1839+ if self ._enable_broker and sys . platform in ( "win32" , "darwin" ) :
18361840 from .broker import _signin_silently
18371841 response = _signin_silently (
18381842 "https://{}/{}" .format (self .authority .instance , self .authority .tenant ),
@@ -1929,13 +1933,15 @@ def __init__(
19291933 * ,
19301934 enable_broker_on_windows = None ,
19311935 enable_broker_on_mac = None ,
1936+ enable_broker_on_linux = None ,
1937+ enable_broker_on_wsl = None ,
19321938 ** kwargs ):
19331939 """Same as :func:`ClientApplication.__init__`,
19341940 except that ``client_credential`` parameter shall remain ``None``.
19351941
19361942 .. note::
19371943
1938- You may set enable_broker_on_windows and/or enable_broker_on_mac to True.
1944+ 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.
19391945
19401946 **What is a broker, and why use it?**
19411947
@@ -1963,9 +1969,11 @@ def __init__(
19631969 if your app is expected to run on Windows 10+
19641970 * ``msauth.com.msauth.unsignedapp://auth``
19651971 if your app is expected to run on Mac
1972+ * ``ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id``
1973+ if your app is expected to run on Linux, especially WSL
19661974
19671975 2. installed broker dependency,
1968- e.g. ``pip install msal[broker]>=1.31 ,<2``.
1976+ e.g. ``pip install msal[broker]>=1.33 ,<2``.
19691977
19701978 3. tested with ``acquire_token_interactive()`` and ``acquire_token_silent()``.
19711979
@@ -2003,12 +2011,29 @@ def __init__(
20032011 This parameter defaults to None, which means MSAL will not utilize a broker.
20042012
20052013 New in MSAL Python 1.31.0.
2014+
2015+ :param boolean enable_broker_on_linux:
2016+ This setting is only effective if your app is running on Linux, including WSL.
2017+ This parameter defaults to None, which means MSAL will not utilize a broker.
2018+
2019+ New in MSAL Python 1.33.0.
2020+
2021+ :param boolean enable_broker_on_wsl:
2022+ This setting is only effective if your app is running on WSL.
2023+ This parameter defaults to None, which means MSAL will not utilize a broker.
2024+
2025+ New in MSAL Python 1.33.0.
20062026 """
20072027 if client_credential is not None :
20082028 raise ValueError ("Public Client should not possess credentials" )
2029+
20092030 self ._enable_broker = bool (
20102031 enable_broker_on_windows and sys .platform == "win32"
2011- or enable_broker_on_mac and sys .platform == "darwin" )
2032+ or enable_broker_on_mac and sys .platform == "darwin"
2033+ or enable_broker_on_linux and sys .platform == "linux"
2034+ or enable_broker_on_wsl and is_wsl ()
2035+ )
2036+
20122037 super (PublicClientApplication , self ).__init__ (
20132038 client_id , client_credential = None , ** kwargs )
20142039
@@ -2137,6 +2162,8 @@ def acquire_token_interactive(
21372162 False
21382163 ) and data .get ("token_type" ) != "ssh-cert" # Work around a known issue as of PyMsalRuntime 0.8
21392164 self ._validate_ssh_cert_input_data (data )
2165+ is_ssh_cert_or_pop_request = _is_ssh_cert_or_pop_request (data .get ("token_type" ), auth_scheme )
2166+
21402167 if not on_before_launching_ui :
21412168 on_before_launching_ui = lambda ** kwargs : None
21422169 if _is_running_in_cloud_shell () and prompt == "none" :
@@ -2145,7 +2172,7 @@ def acquire_token_interactive(
21452172 return self ._acquire_token_by_cloud_shell (scopes , data = data )
21462173 claims = _merge_claims_challenge_and_capabilities (
21472174 self ._client_capabilities , claims_challenge )
2148- if self ._enable_broker :
2175+ if self ._enable_broker and ( sys . platform in ( "win32" , "darwin" ) or not is_ssh_cert_or_pop_request ) :
21492176 if parent_window_handle is None :
21502177 raise ValueError (
21512178 "parent_window_handle is required when you opted into using broker. "
@@ -2170,7 +2197,9 @@ def acquire_token_interactive(
21702197 )
21712198 return self ._process_broker_response (response , scopes , data )
21722199
2173- if auth_scheme :
2200+ if isinstance (auth_scheme , msal .auth_scheme .PopAuthScheme ) and sys .platform == "linux" :
2201+ raise ValueError ("POP is not supported on Linux" )
2202+ elif auth_scheme :
21742203 raise ValueError (self ._AUTH_SCHEME_UNSUPPORTED )
21752204 on_before_launching_ui (ui = "browser" )
21762205 telemetry_context = self ._build_telemetry_context (
0 commit comments