Skip to content

Commit 943cfcc

Browse files
committed
Initial updates for Python on Linux
1 parent 615c776 commit 943cfcc

File tree

1 file changed

+61
-56
lines changed

1 file changed

+61
-56
lines changed

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

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,96 @@
11
---
2-
# Required metadata
3-
# For more information, see https://review.learn.microsoft.com/en-us/help/platform/learn-editor-add-metadata?branch=main
4-
# For valid values of ms.service, ms.prod, and ms.topic, see https://review.learn.microsoft.com/en-us/help/platform/metadata-taxonomies?branch=main
5-
62
title: Using MSAL Python with an Authentication Broker on Linux
73
description: MSAL is able to call Microsoft Single Sign-on for Linux, which is a component that ships as a dependency of Intune Portal. This component acts as an authentication broker allowing the users of your app to benefit from integration with accounts known to the broker.
8-
author: ploegert # GitHub alias
9-
ms.author: jploegert # Microsoft alias
4+
author: ploegert
5+
ms.author: jploegert
106
ms.service: msal
117
ms.topic: how-to
12-
ms.date: 03/18/2025
8+
ms.date: 06/03/2025
139
---
1410

15-
# Using MSAL Python with an Authentication Broker on Linux
11+
# Enable SSSO in native Linux using MSAL Python
1612

13+
Microsoft Authentication Library (MSAL) is a Software Development Kit (SDK) that enables apps to call the Microsoft Single Sign-on to Linux broker, a Linux component that is shipped independent of the Linux Distribution, however it gets installed using a package manager using `sudo apt install microsoft-identity-broker` or `sudo dnf install microsoft-identity-broker`.
1714

18-
> [!NOTE]
19-
> Linux authentication broker support is introduced with `msal` version UPDATE_ME.
15+
This component acts as an authentication broker, allowing the users of your app to benefit from integration with accounts known to Linux - such as the account you signed into your Linux sessions for apps that consume from the broker.
2016

21-
Using an authentication brokers on Linux 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.
17+
The broker is also bundled as a dependency of applications developed by Microsoft (such as [Company Portal](/mem/intune-service/user-help/enroll-device-linux))). An example of installation of the broker being installed is when a Linux computer is enrolled into a company's device fleet via an endpoint management solution like [Microsoft Intune](/mem/intune/fundamentals/what-is-intune).
2218

23-
Authentication brokers are **not** pre-installed on Linux but are applications developed by Microsoft, such as [Company Portal](/mem/intune/apps/apps-company-portal-macos). These applications are usually installed when a Linux 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 Linux device set up with the Microsoft Identity Platform, refer to {TODO} [Microsoft Enterprise SSO plug-in for Apple devices](/entra/identity-platform/apple-sso-plugin).
19+
## What is a broker
2420

25-
1. In the MSAL Python library, we've introduced the `enable_broker_on_linux` flag, which enables the broker on both WSL and standalone Linux. However, if your goal is to enable broker support solely on WSL for Azure CLI, you can consider modifying the Azure CLI app code to activate the `enable_broker_on_linux` flag exclusively on WSL.
21+
An authentication broker is an application that runs on a user’s machine that manages the authentication handshakes and token maintenance for connected accounts. The Linux operating system uses the Microsoft single sign-on for Linux as its authentication broker. It has many benefits for developers and customers alike, including:
2622

27-
1. For WSL, there are no additional dependencies required. The Windows Authentication Manager (WAM), which is available by default on Windows, will serve as the broker. For standalone Linux, you'll need to have the Intune Portal installed for the Linux standalone broker to be set up and running.
23+
- **Enables Single Sign-On**: enables apps to simplify how users authenticate with Microsoft Entra ID and protects Microsoft Entra ID refresh tokens from exfiltration and misuse
24+
- **Enhanced security.** Many security enhancements are delivered with the broker, without needing to update the application logic.
25+
- **Feature support.** With the help of the broker developers can access rich OS and service capabilities.
26+
- **System integration.** Applications that use the broker plug-and-play with the built-in account picker, allowing the user to quickly pick an existing account instead of reentering the same credentials over and over.
27+
- **Token Protection.** Microsoft single sign-on for Linux ensures that the refresh tokens are device bound and [enables apps](../../advanced/proof-of-possession-tokens.md) to acquire device bound access tokens. See [Token Protection](/azure/active-directory/conditional-access/concept-token-protection).
2828

29-
1. If the broker is not installed on standalone Linux, it will fall back to the non-broker authentication flow.
29+
## How to opt in to use broker?
3030

31-
1. If you choose to enable the broker on standalone Linux as well, you would need to test this environment to ensure there is no regression.
31+
1. In the MSAL Python library, we've introduced the `enable_broker_on_linux` flag, which enables the broker on both WSL and standalone Linux.
32+
- If your goal is to enable broker support solely on WSL for Azure CLI, you can consider modifying the Azure CLI app code to activate the `enable_broker_on_wsl` flag exclusively on WSL.
33+
- 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.
34+
- You can set any combination of the following opt-in parameters to true:
3235

33-
## Usage
36+
| Opt-in flag | If app will run on | App has registered this as a Desktop platform redirect URI in Azure Portal |
37+
| ------------------------ | --------------------------------- | -------------------------------------------------------------------------------- |
38+
| enable_broker_on_windows | Windows 10+ | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
39+
| enable_broker_on_wsl | WSL | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
40+
| enable_broker_on_mac | Mac with Company Portal installed | msauth.com.msauth.unsignedapp://auth |
41+
| enable_broker_on_linux | Linux with Intune installed | `https://login.microsoftonline.com/common/oauth2/nativeclient` (MUST be enabled) |
3442

35-
To use the broker, you will need to install the broker-related packages in addition to the core MSAL from PyPI:
43+
2. As shown in the table above, your application needs to support broker-specific redirect URIs. For Linux, the URL must be:
3644

37-
```bash
38-
pip install msal[broker]>=1.31,<2
39-
```
45+
```text
46+
https://login.microsoftonline.com/common/oauth2/nativeclient
47+
```
4048
41-
>[!IMPORTANT]
42-
>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"`.
49+
3. To use the broker, you will need to install the broker-related packages in addition to the core MSAL from PyPI:
4350
44-
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`:
51+
```python
52+
pip install msal[broker]>=1.31,<2
53+
```
4554
46-
```python
47-
from msal import PublicClientApplication
48-
49-
app = PublicClientApplication(
50-
"CLIENT_ID",
51-
authority="https://login.microsoftonline.com/common",
52-
enable_broker_on_mac =True)
53-
```
55+
4. Once configured, you can call `acquire_token_interactive` to acquire a token.
5456
55-
>[!IMPORTANT]
56-
>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.
57+
```python
58+
result = app.acquire_token_interactive(["User.ReadBasic.All"],
59+
parent_window_handle=app.CONSOLE_WINDOW_HANDLE)
60+
```
61+
62+
## Parameters for broker support
5763
58-
In addition to the constructor change, your application needs to support broker-specific redirect URIs. For _unsigned_ applications, the URI is:
64+
The following parameters are available to configure broker support in MSAL Python. These parameters can be passed to the `PublicClientApplication` constructor or to the `acquire_token_interactive` method.
5965
60-
```text
61-
msauth.com.msauth.unsignedapp://auth
62-
```
66+
| Parameters: | Type | Description |
67+
|-------------|------|-------|
68+
| enable_broker_on_windows | `boolean` | This setting is only effective if your app is running on Windows 10+. This parameter defaults to None, which means MSAL will not utilize a broker. </br></br>`New in MSAL Python 1.25.0.` |
69+
| enable_broker_on_wsl | `boolean` | This setting is only effective if your app is running on WSL. This parameter defaults to None, which means MSAL will not utilize a broker. </br></br>`New in MSAL Python 1.25.0`. |
70+
| enable_broker_on_mac | `boolean` | This setting is only effective if your app is running on Mac with Company Portal installed. This parameter defaults to None, which means MSAL will not utilize a broker. </br></br>`New in MSAL Python 1.31.0`.|
71+
| enable_broker_on_linux | `boolean` | This setting is only effective if your app is running on Linux with Intune installed. This parameter defaults to None, which means MSAL will not utilize a broker. </br></br>`New in MSAL Python 1.33.0`. |
72+
| parent_window_handle | `int` | <i>OPTIONAL</i></br> - If your app does not opt in to use broker, you do not need to provide a parent_window_handle here.</br>- If your app opts in to use broker, parent_window_handle is required.</br>If your app is a GUI app running on Windows or Mac system, you are required to also provide its window handle, so that the sign-in window will pop up on top of your window.</br>- If your app is a console app running on Windows or Mac system, you can use a placeholder `PublicClientApplication.CONSOLE_WINDOW_HANDLE`|
6373
64-
For signed applications, the redirect URI should be:
74+
## The fallback behaviors of MSAL Python’s broker support
6575
66-
```text
67-
msauth.BUNDLE_ID://auth
68-
```
76+
MSAL will either error out, or silently fallback to non-broker flows.
6977
70-
If the redirect URIs are not correctly set in the app configuration within the Entra portal, you will receive error like this:
78+
1. MSAL will ignore the enable_broker_… and bypass broker on those auth flows that are known to be NOT supported by broker. This includes ADFS, B2C, etc.. For other “could-use-broker” scenarios, please see below.
7179
72-
```text
73-
Error detected...
74-
tag=508170375
75-
context=AADSTS50011 Description: (pii), Domain: MSAIMSIDOAuthErrorDomain.Error was thrown in location: Broker
76-
errorCode=-51411
77-
status=Response_Status.Status_Unexpected
78-
```
80+
2. MSAL errors out when app developer opted-in to use broker but a direct dependency “mid-tier” package is not installed. Error message guides app developer to declare the correct dependency msal[broker]. We error out here because the error is actionable to app developers.
7981
80-
Once configured, you can call `acquire_token_interactive` to acquire a token.
82+
3. MSAL silently “deactivates” the broker and fallback to non-broker, when opted-in, dependency installed yet failed to initialize. We anticipate this would happen on a device whose OS is too old or the underlying broker component is somehow unavailable. There is not much an app developer or the end user can do here. Eventually, the conditional access policy shall force the user to switch to a different device.
8183
82-
```python
83-
result = app.acquire_token_interactive(["User.ReadBasic.All"],
84-
parent_window_handle=app.CONSOLE_WINDOW_HANDLE)
85-
```
84+
4. MSAL errors out when broker is opted in, installed, initialized, but subsequent token request(s) failed.
85+
86+
>[!IMPORTANT]
87+
>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"`.
88+
89+
>[!IMPORTANT]
90+
>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.
8691
8792
>[!NOTE]
88-
>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.
93+
>The `parent_window_handle` parameter is required even though on Linux 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.
8994
9095
## Token caching
9196

0 commit comments

Comments
 (0)