You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -7,79 +7,182 @@ title: # Add a title for the browser tab
7
7
description: # Add a meaningful description for search results
8
8
author: ploegert # GitHub alias
9
9
ms.author: jploegert # Microsoft alias
10
-
ms.service: # Add the ms.service or ms.prod value
10
+
ms.service: msal
11
11
# ms.prod: # To use ms.prod, uncomment it and delete ms.service
12
-
ms.topic: # Add the ms.topic value
13
-
ms.date: 03/18/2025
12
+
ms.topic: how-to
13
+
ms.date: 05/08/2025
14
14
---
15
15
16
-
# Using MSAL .NET with an Authentication Broker on Linux
17
-
16
+
# Use MSAL.NET with an authentication broker on Linux
18
17
19
18
> [!NOTE]
20
-
> Microsoft Single Sign-on for Linux authentication broker support is introduced with `MSAL` version v4.69.1.
19
+
> Microsoft single sign-on (SSO) for Linux authentication broker support is introduced with `Microsoft.Identity.Client` version v4.69.1.
21
20
22
21
Using an authentication broker 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.
23
22
24
-
Authentication brokers are **not** pre-installed on Linux but is bundled as a dependency of applications developed by Microsoft, such as [Company Portal](/mem/intune-service/user-help/enroll-device-linux). 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[Microsoft Enterprise SSO plug-in for Apple devices](/entra/identity-platform/apple-sso-plugin).
23
+
An authentication broker is **not** pre-installed on standalone Linux but is bundled as a dependency of applications developed by Microsoft, such as [Company Portal](/mem/intune-service/user-help/enroll-device-linux). 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). For [Windows Subsystem for Linux](/windows/wsl/about) (WSL) scenario, WAM (Windows Account Manager) is used as the broker. WAM does come pre-installed on the Windows system. To learn more about Linux device set up with the Microsoft Identity Platform, see[Microsoft Enterprise SSO plug-in for Apple devices](/entra/identity-platform/apple-sso-plugin).
25
24
26
-
## Usage
25
+
## Prerequisites
27
26
28
-
To use the broker, you will need to install the broker-related packages in addition to the core MSAL from PyPI:
27
+
To use the broker, you'll need to install a list of dependencies on the Linux platform:
29
28
30
29
```bash
31
-
pip install msal[broker]>=1.31,<2
30
+
libc++-dev
31
+
libc++abi-dev
32
+
libsecret-tools
33
+
libwebkit2gtk-4.0
32
34
```
33
35
34
-
>[!IMPORTANT]
35
-
>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"`.
36
36
37
-
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`:
37
+
## Create a console app on Linux platform
38
+
39
+
To use a broker on the Linux platform, set the `BrokerOptions` to `OperatingSystems.Linux`. Notice that we use the same option for both Windows Subsystem for Linux (WSL) and standalone Linux.
>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.
70
+
## Sample App
71
+
A sample application is available for developers who want to try the authentication broker on Linux. The application is located [in the MSAL.NET GitHub repository](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/tree/main/tests/devapps/WAM/NetWSLWam). The app has a dependency of `libx11-dev` package.
50
72
51
-
In addition to the constructor change, your application needs to support broker-specific redirect URIs. For _unsigned_ applications, the URI is:
73
+
On Debian-based distributions, run `sudo apt install libx11-dev`to install the package. The `libx11` library is used to get the console window handle on Linux. Here's the sample code to use `libx11` to get the window handle:
52
74
53
-
```text
54
-
msauth.com.msauth.unsignedapp://auth
55
-
```
75
+
```csharp
76
+
usingSystem;
77
+
usingSystem.Runtime.InteropServices;
56
78
57
-
For signed applications, the redirect URI should be:
dotnet run --project tests\devapps\WAM\NetWSLWam\test.csproj
61
105
```
62
106
63
-
If the redirect URIs are not correctly set in the app configuration within the Entra portal, you will receive error like this:
107
+
## WSL Scenario
64
108
65
-
```text
66
-
Error detected...
67
-
tag=508170375
68
-
context=AADSTS50011 Description: (pii), Domain: MSAIMSIDOAuthErrorDomain.Error was thrown in location: Broker
69
-
errorCode=-51411
70
-
status=Response_Status.Status_Unexpected
109
+
### Update to the latest version of WSL
110
+
111
+
Enure you have updated to the latest WSL release. The WAM Account Control dialog is supported in WSL versions 2.4.13 and above. Using the broker isn't possible with earlier versions.
112
+
113
+
```powershell
114
+
115
+
#to start from scratch:
116
+
wsl --unregister Ubuntu-22.04
117
+
118
+
#To check what distros are available:
119
+
wsl.exe --list --online
120
+
121
+
wsl.exe --install Ubuntu-22.04
122
+
123
+
# To check the WSL version, use the following command:
124
+
wsl --version
125
+
126
+
# To update WSL, run the following command from Windows Terminal:
127
+
wsl --update
71
128
```
72
129
73
-
Once configured, you can call `acquire_token_interactive` to acquire a token.
cd /mnt/c/git/microsoft-authentication-library-for-dotnet/tests/devapps/WAM/NetWSLWam/
155
+
dotnet build
156
+
donet run
157
+
158
+
#Or do this
159
+
cd /mnt/c/git/microsoft-authentication-library-for-dotnet
160
+
dotnet run --project tests/devapps/WAM/NetWSLWam/test.csproj
74
161
75
-
```python
76
-
result = app.acquire_token_interactive(["User.ReadBasic.All"],
77
-
parent_window_handle=app.CONSOLE_WINDOW_HANDLE)
78
162
```
79
163
80
-
>[!NOTE]
81
-
>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.
82
164
83
-
## Token caching
165
+
### Set up Keyring in WSL
166
+
MSAL uses `libsecret` on Linux. It is required to communicate with the `keyring` daemon. Users can use [Seahorse](https://wiki.gnome.org/Apps/Seahorse/) (a GNOME application for managing encryption keys and passwords) to manage the `keyring` contents through a Graphical User Interface (GUI).
167
+
168
+
On Debian-based distributions, you can install the package by running `sudo apt install seahorse` and then following these instructions:
169
+
170
+
1. Run `seahorse` in the terminal.
171
+
172
+

173
+
174
+
2. In the top left corner, click **+** and create **Password** keyring.
175
+
176
+

177
+
178
+
3. Create a keyring named 'login'
179
+
180
+

181
+
182
+
4. Set the password on the next dialog.
183
+

184
+
185
+
5. Run `wsl.exe --shutdown` from your Windows Terminal.
186
+
187
+
6. Start a new WSL session and run the sample. You should be asked for the keyring password.
84
188
85
-
The authentication broker handles refresh and access token caching. You do not need to set up custom caching.
0 commit comments