Skip to content

Commit 36d7cc2

Browse files
authored
Merge pull request #102 from MicrosoftDocs/main
Sync macOS article
2 parents aed2f21 + 312e39e commit 36d7cc2

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

msal-python-conceptual/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
items:
1212
- name: Using MSAL Python with Web Account Manager
1313
href: advanced/wam.md
14+
- name: Using MSAL Python with Authentication Brokers on macOS
15+
href: advanced/macos-broker.md
1416
- name: Migrate to MSAL Python
1517
href: advanced/migrate-python-adal-msal.md
1618
- name: Logging
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: Using MSAL Python with an Authentication Broker on macOS
3+
description: "Using an authentication broker on macOS enables you to simplify how your users authenticate with Microsoft Entra ID from your application, as well as take advantage of advanced functionality such as token binding, protecting any issued tokens from exfiltration and misuse."
4+
author: localden
5+
manager: CelesteDG
6+
7+
ms.service: msal
8+
ms.subservice: msal-python
9+
ms.topic: conceptual
10+
ms.date: 09/06/2024
11+
ms.author: ddelimarsky
12+
ms.reviewer: shermanouko, rayluo
13+
---
14+
15+
# Using MSAL Python with an Authentication Broker on macOS
16+
17+
>[!NOTE]
18+
>macOS authentication broker support is introduced with `msal` version 1.31.0.
19+
20+
Using an authentication brokers on macOS enables you to simplify how your users authenticate with Microsoft Entra ID from your application,
21+
as well as take advantage of future functionality that protects Microsoft Entra ID refresh tokens from exfiltration and misuse.
22+
23+
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).
24+
25+
## Usage
26+
27+
To use the broker, you will need to install the broker-related packages in addition to the core MSAL from PyPI:
28+
29+
```bash
30+
pip install msal[broker]>=1.31,<2
31+
```
32+
33+
>[!IMPORTANT]
34+
>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"`.
35+
36+
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+
38+
```python
39+
from msal import PublicClientApplication
40+
41+
app = PublicClientApplication(
42+
"CLIENT_ID",
43+
authority="https://login.microsoftonline.com/common",
44+
enable_broker_on_mac =True)
45+
```
46+
47+
>[!IMPORTANT]
48+
>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.
49+
50+
In addition to the constructor change, your application needs to support broker-specific redirect URIs. For _unsigned_ applications, the URI is:
51+
52+
```text
53+
msauth.com.msauth.unsignedapp://auth
54+
```
55+
56+
For signed applications, the redirect URI should be:
57+
58+
```text
59+
msauth.BUNDLE_ID://auth
60+
```
61+
62+
If the redirect URIs are not correctly set in the app configuration within the Entra portal, you will receive error like this:
63+
64+
```text
65+
Error detected...
66+
tag=508170375
67+
context=AADSTS50011 Description: (pii), Domain: MSAIMSIDOAuthErrorDomain.Error was thrown in location: Broker
68+
errorCode=-51411
69+
status=Response_Status.Status_Unexpected
70+
```
71+
72+
Once configured, you can call `acquire_token_interactive` to acquire a token.
73+
74+
```python
75+
result = app.acquire_token_interactive(["User.ReadBasic.All"],
76+
parent_window_handle=app.CONSOLE_WINDOW_HANDLE)
77+
```
78+
79+
>[!NOTE]
80+
>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.
81+
82+
## Token caching
83+
84+
The authentication broker handles refresh and access token caching. You do not need to set up custom caching.

msal-python-conceptual/advanced/wam.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ pip install msal[broker]>=1.20,<2
3232
>[!IMPORTANT]
3333
>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.20,<2"`.
3434
35-
Next, you will need to instantiate a new [`PublicClientApplication`](xref:msal.application.PublicClientApplication) and set `allow_broker` to `True`. This will ensure that MSAL will try and communicate with WAM instead of popping up a new browser window.
35+
Next, you will need to instantiate a new [`PublicClientApplication`](xref:msal.application.PublicClientApplication) and set `enable_broker_on_windows` to `True`. This will ensure that MSAL will try and communicate with WAM instead of popping up a new browser window.
36+
37+
>[!IMPORTANT]
38+
>If you are writing a cross-platform application, you will also need to use `enable_broker_on_mac`, as outlined in the [Using MSAL Python with an Authentication Broker on macOS](macos-broker.md) article.
3639
3740
```python
3841
from msal import PublicClientApplication
3942

4043
app = PublicClientApplication(
4144
"CLIENT_ID",
4245
authority="https://login.microsoftonline.com/common",
43-
allow_broker=True)
46+
enable_broker_on_windows=True)
4447
```
4548

4649
You can now acquire a token by calling [`acquire_token_interactive`](xref:msal.application.PublicClientApplication.acquire_token_interactive) and specifying a parent window handle through `parent_window_handle`:

msal-python-conceptual/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"breadcrumb_path": "/entra/msal/python/breadcrumb/toc.json",
4545
"extendBreadcrumb": true,
4646
"uhfHeaderId": "MSDocsHeader-Entra",
47-
"feedback_system": "GitHub",
47+
"feedback_system": "OpenSource",
4848
"feedback_github_repo": "MicrosoftDocs/microsoft-authentication-library-for-python",
4949
"feedback_product_url": "https://github.com/AzureAD/microsoft-authentication-library-for-python/issues",
5050
"recommendations": true,

0 commit comments

Comments
 (0)