Skip to content

Commit 5742035

Browse files
committed
allow_broker becomes conditional per platform
1 parent 545e856 commit 5742035

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

msal/application.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def __init__(
450450
This factor would become mandatory
451451
if a tenant's admin enables a corresponding Conditional Access (CA) policy.
452452
The broker's presence allows Microsoft identity platform
453-
to have higher confidence that the tokens are being issued to your device,
453+
to have more confidence that the tokens are being issued to your device,
454454
and that is more secure.
455455
456456
An additional benefit of broker is,
@@ -459,29 +459,24 @@ def __init__(
459459
so that your broker-enabled apps (even a CLI)
460460
could automatically SSO from a previously established signed-in session.
461461
462-
This parameter defaults to None, which means MSAL will not utilize a broker.
463-
If this parameter is set to True,
464-
MSAL will use the broker whenever possible,
465-
and automatically fall back to non-broker behavior.
466-
That also means your app does not need to enable broker conditionally,
467-
you can always set allow_broker to True,
468-
as long as your app meets the following prerequisite:
462+
This parameter defaults to None, which means MSAL will not utilize a broker,
463+
and your end users will have the traditional browser-based login experience.
469464
470-
* Installed optional dependency, e.g. ``pip install msal[broker]>=1.20,<2``.
471-
(Note that broker is currently only available on Windows 10+)
465+
You can set it to True, based on the OS platform.
466+
Currently, MSAL supports broker on Windows 10+, and errors out on others.
467+
So, for example, you can do ``allow_broker = sys.platform=="win32"``.
472468
473-
* Register a new redirect_uri for your desktop app as:
474-
``ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id``
475-
476-
* Tested your app in following scenarios:
469+
In order to allow broker, your app must also meet the following prerequisite:
477470
478-
* Windows 10+
471+
* Install optional dependency, e.g. ``pip install msal[broker]>=1.20,<2``.
479472
480-
* PublicClientApplication's following methods::
481-
acquire_token_interactive(), acquire_token_by_username_password(),
482-
acquire_token_silent() (or acquire_token_silent_with_error()).
473+
* Register a new redirect_uri for your desktop app as:
474+
``ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id``
483475
484-
* AAD and MSA accounts (i.e. Non-ADFS, non-B2C)
476+
* Test your app with AAD and MSA accounts (i.e. Non-ADFS, non-B2C)
477+
in PublicClientApplication's following methods:
478+
acquire_token_interactive(), acquire_token_by_username_password(),
479+
acquire_token_silent() (or acquire_token_silent_with_error()).
485480
486481
New in version 1.20.0.
487482
"""
@@ -549,6 +544,9 @@ def __init__(
549544
)
550545
else:
551546
raise
547+
548+
if allow_broker and sys.platform != "win32":
549+
raise ValueError("allow_broker=True is only supported on Windows")
552550
is_confidential_app = bool(
553551
isinstance(self, ConfidentialClientApplication) or self.client_credential)
554552
if is_confidential_app and allow_broker:

sample/interactive_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Create a preferably long-lived app instance which maintains a token cache.
3434
app = msal.PublicClientApplication(
3535
config["client_id"], authority=config["authority"],
36-
#allow_broker=True, # If opted in, you will be guided to meet the prerequisites, when applicable
36+
#allow_broker=sys.platform in ["win32"], # If opted in, you will be guided to meet the prerequisites, when applicable
3737
# See also: https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-acquire-token-wam#wam-value-proposition
3838
# token_cache=... # Default cache is in memory only.
3939
# You can learn how to use SerializableTokenCache from

tests/test_application.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,17 @@ def test_organizations_authority_should_emit_warnning(self):
625625
self._test_certain_authority_should_emit_warnning(
626626
authority="https://login.microsoftonline.com/organizations")
627627

628+
629+
class TestBrokerAllowance(unittest.TestCase):
630+
def test_opt_in_for_broker_should_error_out_on_nonsupported_platforms(self):
631+
supported_platforms = ["win32"]
632+
if sys.platform in supported_platforms:
633+
try:
634+
PublicClientApplication("client_id", allow_broker=True)
635+
# It would either create an app instance successfully
636+
except ImportError:
637+
pass # Or detect the absence of MsalRuntime
638+
else:
639+
with self.assertRaises(ValueError): # We decide to error out
640+
PublicClientApplication("client_id", allow_broker=True)
641+

0 commit comments

Comments
 (0)