Skip to content

Commit 830ae13

Browse files
committed
Learn Editor: Update linux-broker-py.md
1 parent fb2858d commit 830ae13

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

msal-python-conceptual/advanced/linux-broker-py.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,75 @@ ms.topic: # Add the ms.topic value
1313
ms.date: 03/18/2025
1414
---
1515

16-
Using MSAL Python with an Authentication Broker on Linux
16+
# Using MSAL Python with an Authentication Broker on Linux
17+
18+
19+
# Using MSAL Python with an Authentication Broker on macOS
20+
21+
> [!NOTE]
22+
> Linux authentication broker support is introduced with `msal` version UPDATE_ME.
23+
24+
Using an authentication brokers on macOS enables you to simplify how your users authenticate with Microsoft Entra ID from your application, as well as take advantage of future functionality that protects Microsoft Entra ID refresh tokens from exfiltration and misuse.
25+
26+
Authentication brokers are **not** pre-installed on macOS but are applications developed by Microsoft, such as [Company Portal](/mem/intune/apps/apps-company-portal-macos). These applications are usually installed when a macOS computer is enrolled in a company's device fleet via an endpoint management solution like [Microsoft Intune](/mem/intune/fundamentals/what-is-intune). To learn more about Apple device set up with the Microsoft Identity Platform, refer to [Microsoft Enterprise SSO plug-in for Apple devices](/entra/identity-platform/apple-sso-plugin).
27+
28+
## Usage
29+
30+
To use the broker, you will need to install the broker-related packages in addition to the core MSAL from PyPI:
31+
32+
```bash
33+
pip install msal[broker]>=1.31,<2
34+
```
35+
36+
>[!IMPORTANT]
37+
>If broker-related packages are not installed and you will try to use the authentication broker, you will get an error: `ImportError: You need to install dependency by: pip install "msal[broker]>=1.31,<2"`.
38+
39+
Typically, on macOS your [public client](/entra/identity-platform/msal-client-applications) Python applications would [acquire tokens](../getting-started/acquiring-tokens.md) via the system browser. To use authentication brokers installed on a macOS system instead, you will need to pass an additional argument in the `PublicClientApplication` constructor - `enable_broker_on_mac`:
40+
41+
```python
42+
from msal import PublicClientApplication
43+
44+
app = PublicClientApplication(
45+
"CLIENT_ID",
46+
authority="https://login.microsoftonline.com/common",
47+
enable_broker_on_mac =True)
48+
```
49+
50+
>[!IMPORTANT]
51+
>If you are writing a cross-platform application, you will also need to use `enable_broker_on_windows`, as outlined in the [Using MSAL Python with Web Account Manager](wam.md) article.
52+
53+
In addition to the constructor change, your application needs to support broker-specific redirect URIs. For _unsigned_ applications, the URI is:
54+
55+
```text
56+
msauth.com.msauth.unsignedapp://auth
57+
```
58+
59+
For signed applications, the redirect URI should be:
60+
61+
```text
62+
msauth.BUNDLE_ID://auth
63+
```
64+
65+
If the redirect URIs are not correctly set in the app configuration within the Entra portal, you will receive error like this:
66+
67+
```text
68+
Error detected...
69+
tag=508170375
70+
context=AADSTS50011 Description: (pii), Domain: MSAIMSIDOAuthErrorDomain.Error was thrown in location: Broker
71+
errorCode=-51411
72+
status=Response_Status.Status_Unexpected
73+
```
74+
75+
Once configured, you can call `acquire_token_interactive` to acquire a token.
76+
77+
```python
78+
result = app.acquire_token_interactive(["User.ReadBasic.All"],
79+
parent_window_handle=app.CONSOLE_WINDOW_HANDLE)
80+
```
81+
82+
>[!NOTE]
83+
>The `parent_window_handle` parameter is required even though on macOS it is not used. For GUI applications, the login prompt location will be determined ad-hoc and currently cannot be bound to a specific window. In a future update, this parameter will be used to determine the _actual_ parent window.
84+
85+
## Token caching
86+
87+
The authentication broker handles refresh and access token caching. You do not need to set up custom caching.

0 commit comments

Comments
 (0)