21
21
from .throttled_http_client import ThrottledHttpClient
22
22
from .cloudshell import _is_running_in_cloud_shell
23
23
from .sku import SKU , __version__
24
-
24
+ from . oauth2cli . authcode import is_wsl
25
25
26
26
27
27
logger = logging .getLogger (__name__ )
@@ -164,6 +164,8 @@ def _preferred_browser():
164
164
pass # We may still proceed
165
165
return None
166
166
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 )
167
169
168
170
class _ClientWithCcsRoutingInfo (Client ):
169
171
@@ -710,7 +712,7 @@ def _decide_broker(self, allow_broker, enable_pii_log):
710
712
711
713
def is_pop_supported (self ):
712
714
"""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" )
714
716
715
717
def _decorate_scope (
716
718
self , scopes ,
@@ -1582,10 +1584,12 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
1582
1584
raise ValueError ("auth_scheme is not supported in Cloud Shell" )
1583
1585
return self ._acquire_token_by_cloud_shell (scopes , data = data )
1584
1586
1587
+ is_ssh_cert_or_pop_request = _is_ssh_cert_or_pop_request (data .get ("token_type" ), auth_scheme )
1588
+
1585
1589
if self ._enable_broker and account and account .get ("account_source" ) in (
1586
1590
_GRANT_TYPE_BROKER , # Broker successfully established this account previously.
1587
1591
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 ) :
1589
1593
from .broker import _acquire_token_silently
1590
1594
response = _acquire_token_silently (
1591
1595
"https://{}/{}" .format (self .authority .instance , self .authority .tenant ),
@@ -1832,7 +1836,7 @@ def acquire_token_by_username_password(
1832
1836
"""
1833
1837
claims = _merge_claims_challenge_and_capabilities (
1834
1838
self ._client_capabilities , claims_challenge )
1835
- if self ._enable_broker :
1839
+ if self ._enable_broker and sys . platform in ( "win32" , "darwin" ) :
1836
1840
from .broker import _signin_silently
1837
1841
response = _signin_silently (
1838
1842
"https://{}/{}" .format (self .authority .instance , self .authority .tenant ),
@@ -1929,13 +1933,15 @@ def __init__(
1929
1933
* ,
1930
1934
enable_broker_on_windows = None ,
1931
1935
enable_broker_on_mac = None ,
1936
+ enable_broker_on_linux = None ,
1937
+ enable_broker_on_wsl = None ,
1932
1938
** kwargs ):
1933
1939
"""Same as :func:`ClientApplication.__init__`,
1934
1940
except that ``client_credential`` parameter shall remain ``None``.
1935
1941
1936
1942
.. note::
1937
1943
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.
1939
1945
1940
1946
**What is a broker, and why use it?**
1941
1947
@@ -1963,9 +1969,11 @@ def __init__(
1963
1969
if your app is expected to run on Windows 10+
1964
1970
* ``msauth.com.msauth.unsignedapp://auth``
1965
1971
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
1966
1974
1967
1975
2. installed broker dependency,
1968
- e.g. ``pip install msal[broker]>=1.31 ,<2``.
1976
+ e.g. ``pip install msal[broker]>=1.33 ,<2``.
1969
1977
1970
1978
3. tested with ``acquire_token_interactive()`` and ``acquire_token_silent()``.
1971
1979
@@ -2003,12 +2011,29 @@ def __init__(
2003
2011
This parameter defaults to None, which means MSAL will not utilize a broker.
2004
2012
2005
2013
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.
2006
2026
"""
2007
2027
if client_credential is not None :
2008
2028
raise ValueError ("Public Client should not possess credentials" )
2029
+
2009
2030
self ._enable_broker = bool (
2010
2031
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
+
2012
2037
super (PublicClientApplication , self ).__init__ (
2013
2038
client_id , client_credential = None , ** kwargs )
2014
2039
@@ -2137,6 +2162,8 @@ def acquire_token_interactive(
2137
2162
False
2138
2163
) and data .get ("token_type" ) != "ssh-cert" # Work around a known issue as of PyMsalRuntime 0.8
2139
2164
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
+
2140
2167
if not on_before_launching_ui :
2141
2168
on_before_launching_ui = lambda ** kwargs : None
2142
2169
if _is_running_in_cloud_shell () and prompt == "none" :
@@ -2145,7 +2172,7 @@ def acquire_token_interactive(
2145
2172
return self ._acquire_token_by_cloud_shell (scopes , data = data )
2146
2173
claims = _merge_claims_challenge_and_capabilities (
2147
2174
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 ) :
2149
2176
if parent_window_handle is None :
2150
2177
raise ValueError (
2151
2178
"parent_window_handle is required when you opted into using broker. "
@@ -2170,7 +2197,9 @@ def acquire_token_interactive(
2170
2197
)
2171
2198
return self ._process_broker_response (response , scopes , data )
2172
2199
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 :
2174
2203
raise ValueError (self ._AUTH_SCHEME_UNSUPPORTED )
2175
2204
on_before_launching_ui (ui = "browser" )
2176
2205
telemetry_context = self ._build_telemetry_context (
0 commit comments