@@ -177,6 +177,8 @@ class ClientApplication(object):
177177
178178 ATTEMPT_REGION_DISCOVERY = True # "TryAutoDetect"
179179
180+ _enable_broker = False
181+
180182 def __init__ (
181183 self , client_id ,
182184 client_credential = None , authority = None , validate_authority = True ,
@@ -194,7 +196,6 @@ def __init__(
194196 instance_discovery = None ,
195197 allow_broker = None ,
196198 enable_pii_log = None ,
197- enable_broker = None ,
198199 ):
199200 """Create an instance of application.
200201
@@ -467,51 +468,7 @@ def __init__(
467468 New in version 1.19.0.
468469
469470 :param boolean allow_broker:
470- Deprecated. It will only work on Windows platform.
471- Please use ``enable_broker`` instead.
472-
473- :param boolean enable_broker:
474- This parameter is NOT applicable to :class:`ConfidentialClientApplication`.
475-
476- This setting is platform-dependent.
477- We currently support Windows 10+ and Mac.
478- You shall only enable broker when your app:
479-
480- 1. is running on supported platforms,
481- and already registered their corresponding redirect_uri
482-
483- * ``ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id``
484- if your app is expected to run on Windows 10+
485- * ``msauth.com.msauth.unsignedapp://auth``
486- if your app is expected to run on Mac
487-
488- 2. installed broker dependency,
489- e.g. ``pip install msal[broker]>=1.24,<2``.
490-
491- 3. tested with ``acquire_token_interactive()`` at least.
492-
493- This parameter defaults to None,
494- which means MSAL will not utilize a broker.
495-
496- What is a broker, and why use it?
497-
498- A broker is a component installed on your device.
499- Broker implicitly gives your device an identity. By using a broker,
500- your device becomes a factor that can satisfy MFA (Multi-factor authentication).
501- This factor would become mandatory
502- if a tenant's admin enables a corresponding Conditional Access (CA) policy.
503- The broker's presence allows Microsoft identity platform
504- to have higher confidence that the tokens are being issued to your device,
505- and that is more secure.
506-
507- An additional benefit of broker is,
508- it runs as a long-lived process with your device's OS,
509- and maintains its own cache,
510- so that your broker-enabled apps (even a CLI)
511- could automatically SSO from a previously established signed-in session.
512-
513- Note: ADFS and B2C do not support broker.
514- MSAL will automatically fallback to use browser.
471+ Deprecated. Please use ``enable_broker_on_windows`` instead.
515472
516473 :param boolean enable_pii_log:
517474 When enabled, logs may include PII (Personal Identifiable Information).
@@ -585,10 +542,7 @@ def __init__(
585542 else :
586543 raise
587544
588- self ._enable_broker = self ._decide_broker (
589- enable_broker = enable_broker , allow_broker = allow_broker ,
590- enable_pii_log = enable_pii_log ,
591- )
545+ self ._decide_broker (allow_broker , enable_pii_log )
592546 self .token_cache = token_cache or TokenCache ()
593547 self ._region_configured = azure_region
594548 self ._region_detected = None
@@ -598,45 +552,35 @@ def __init__(
598552 self ._telemetry_buffer = {}
599553 self ._telemetry_lock = Lock ()
600554
601- def _decide_broker (
602- self ,
603- enable_broker = None ,
604- allow_broker = None ,
605- enable_pii_log = None ,
606- ):
607- _enable_broker = False
608- is_confidential_app = bool (
609- isinstance (self , ConfidentialClientApplication ) or self .client_credential )
555+ def _decide_broker (self , allow_broker , enable_pii_log ):
556+ is_confidential_app = self .client_credential or isinstance (
557+ self , ConfidentialClientApplication )
610558 if is_confidential_app and allow_broker :
611559 raise ValueError ("allow_broker=True is only supported in PublicClientApplication" )
560+ # Historically, we chose to support ClientApplication("client_id", allow_broker=True)
612561 if allow_broker :
613562 warnings .warn (
614563 "allow_broker is deprecated. "
615- "Please use enable_broker conditionally per platform. " ,
564+ "Please use enable_broker_on_windows and/or enable_broker_on_mac " ,
616565 DeprecationWarning )
617- if is_confidential_app and enable_broker :
618- raise ValueError ("enable_broker=True is only supported in PublicClientApplication" )
619- if enable_broker and sys .platform not in ["win32" , "darwin" ]:
620- raise ValueError ("enable_broker can only run on Windows or Mac" )
621- opts_in = enable_broker or (
566+ self ._enable_broker = self ._enable_broker or (
622567 # When we started the broker project on Windows platform,
623568 # the allow_broker was meant to be cross-platform. Now we realize
624569 # that other platforms have different redirect_uri requirements,
625570 # so the old allow_broker is deprecated and will only for Windows.
626571 allow_broker and sys .platform == "win32" )
627- if (opts_in and not is_confidential_app
572+ if (self . _enable_broker and not is_confidential_app
628573 and not self .authority .is_adfs and not self .authority ._is_b2c ):
629574 try :
630575 from . import broker # Trigger Broker's initialization
631576 if enable_pii_log :
632577 broker ._enable_pii_log ()
633- _enable_broker = True
634578 except RuntimeError :
579+ self ._enable_broker = False
635580 logger .exception (
636581 "Broker is unavailable on this platform. "
637582 "We will fallback to non-broker." )
638- logger .debug ("Broker enabled? %s" , _enable_broker )
639- return _enable_broker
583+ logger .debug ("Broker enabled? %s" , self ._enable_broker )
640584
641585 def _decorate_scope (
642586 self , scopes ,
@@ -1759,9 +1703,62 @@ class PublicClientApplication(ClientApplication): # browser app or mobile app
17591703 def __init__ (self , client_id , client_credential = None , ** kwargs ):
17601704 """Same as :func:`ClientApplication.__init__`,
17611705 except that ``client_credential`` parameter shall remain ``None``.
1706+
1707+ .. note::
1708+
1709+ You may set enable_broker_on_windows and/or enable_broker_on_mac to True.
1710+
1711+ What is a broker, and why use it?
1712+
1713+ A broker is a component installed on your device.
1714+ Broker implicitly gives your device an identity. By using a broker,
1715+ your device becomes a factor that can satisfy MFA (Multi-factor authentication).
1716+ This factor would become mandatory
1717+ if a tenant's admin enables a corresponding Conditional Access (CA) policy.
1718+ The broker's presence allows Microsoft identity platform
1719+ to have higher confidence that the tokens are being issued to your device,
1720+ and that is more secure.
1721+
1722+ An additional benefit of broker is,
1723+ it runs as a long-lived process with your device's OS,
1724+ and maintains its own cache,
1725+ so that your broker-enabled apps (even a CLI)
1726+ could automatically SSO from a previously established signed-in session.
1727+
1728+ ADFS and B2C do not support broker.
1729+ MSAL will automatically fallback to use browser.
1730+
1731+ You shall only enable broker when your app:
1732+
1733+ 1. is running on supported platforms,
1734+ and already registered their corresponding redirect_uri
1735+
1736+ * ``ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id``
1737+ if your app is expected to run on Windows 10+
1738+ * ``msauth.com.msauth.unsignedapp://auth``
1739+ if your app is expected to run on Mac
1740+
1741+ 2. installed broker dependency,
1742+ e.g. ``pip install msal[broker]>=1.25,<2``.
1743+
1744+ 3. tested with ``acquire_token_interactive()`` at least.
1745+
1746+ :param boolean enable_broker_on_windows:
1747+ This setting is only effective if your app is running on Windows 10+.
1748+ This parameter defaults to None, which means MSAL will not utilize a broker.
1749+
1750+ :param boolean enable_broker_on_mac:
1751+ This setting is only effective if your app is running on Mac.
1752+ This parameter defaults to None, which means MSAL will not utilize a broker.
17621753 """
17631754 if client_credential is not None :
17641755 raise ValueError ("Public Client should not possess credentials" )
1756+ # Using kwargs notation for now. We will switch to keyword-only arguments.
1757+ enable_broker_on_windows = kwargs .pop ("enable_broker_on_windows" , False )
1758+ enable_broker_on_mac = kwargs .pop ("enable_broker_on_mac" , False )
1759+ self ._enable_broker = bool (
1760+ enable_broker_on_windows and sys .platform == "win32"
1761+ or enable_broker_on_mac and sys .platform == "darwin" )
17651762 super (PublicClientApplication , self ).__init__ (
17661763 client_id , client_credential = None , ** kwargs )
17671764
@@ -2073,7 +2070,7 @@ def acquire_token_by_device_flow(self, flow, claims_challenge=None, **kwargs):
20732070
20742071class ConfidentialClientApplication (ClientApplication ): # server-side web app
20752072 """Same as :func:`ClientApplication.__init__`,
2076- except that ``allow_broker`` and ``enable_broker`` parameters shall remain ``None``.
2073+ except that ``allow_broker`` parameter shall remain ``None``.
20772074 """
20782075
20792076 def acquire_token_for_client (self , scopes , claims_challenge = None , ** kwargs ):
0 commit comments