Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2d2853f
Extracted broker auth into new doc
alexwolfmsft Aug 20, 2025
162869a
fix metadata
alexwolfmsft Aug 20, 2025
835f844
fix toc
alexwolfmsft Aug 20, 2025
5d910e0
Apply suggestions from code review
alexwolfmsft Aug 20, 2025
8fc22b8
Apply suggestions from code review
alexwolfmsft Aug 21, 2025
df06fe4
Apply suggestions from code review
alexwolfmsft Aug 21, 2025
04ba363
Apply suggestions from code review
alexwolfmsft Aug 21, 2025
fdc226f
temp
alexwolfmsft Aug 25, 2025
f85473b
temp
alexwolfmsft Aug 25, 2025
881a038
add additional OS
alexwolfmsft Aug 25, 2025
2761f6c
fix zone pivots
alexwolfmsft Aug 25, 2025
ca6362f
Maui fixes
alexwolfmsft Aug 25, 2025
61f5d96
fix code blocks
alexwolfmsft Aug 25, 2025
4759332
refactor intro
alexwolfmsft Aug 25, 2025
d410988
fixes
alexwolfmsft Aug 25, 2025
ede3fa1
fixes
alexwolfmsft Aug 25, 2025
5892f9d
fix code lines
alexwolfmsft Aug 26, 2025
6e787bd
fixes
alexwolfmsft Aug 26, 2025
893b0bc
changes
alexwolfmsft Aug 26, 2025
ec7ac00
fixes
alexwolfmsft Aug 26, 2025
08ef06a
fixes
alexwolfmsft Aug 26, 2025
d7e79fc
fixes
alexwolfmsft Aug 26, 2025
e031539
fixes
alexwolfmsft Aug 26, 2025
dcab7fe
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
9b58686
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
7d3fd3a
PR Fixes
alexwolfmsft Aug 26, 2025
c836ded
update
alexwolfmsft Aug 26, 2025
8ff30d2
code update
alexwolfmsft Aug 26, 2025
e0d208e
fix secrets
alexwolfmsft Aug 26, 2025
9a606ac
remove secret
alexwolfmsft Aug 26, 2025
420e5c9
fix compile
alexwolfmsft Aug 26, 2025
8f95647
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
b530aec
zone pivot change
alexwolfmsft Aug 26, 2025
d07511e
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
c26c551
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
8896a4f
Merge
alexwolfmsft Aug 26, 2025
5e09236
Merge branch 'new-broker-auth-doc' of https://github.com/alexwolfmsft…
alexwolfmsft Aug 26, 2025
8fdcde2
fixes
alexwolfmsft Aug 26, 2025
4db4afe
Apply suggestions from code review
alexwolfmsft Aug 26, 2025
f2af6cd
Add macOS screenshot
scottaddie Aug 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions docs/azure/sdk/authentication/additional-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,6 @@ The following example demonstrates using an [`InteractiveBrowserCredential`](/do

For more exact control, such as setting redirect URIs, you can supply specific arguments to `InteractiveBrowserCredential` such as `redirect_uri`.

## Interactive brokered authentication

This method interactively authenticates an application through <xref:Azure.Identity.InteractiveBrowserCredential> by collecting user credentials using the system authentication broker. A system authentication broker is an app running on a user's machine that manages the authentication handshakes and token maintenance for all connected accounts. Currently, only the Windows authentication broker, Web Account Manager (WAM), is supported. Users on macOS and Linux will be authenticated through the non-brokered interactive browser flow.

WAM enables identity providers such as Microsoft Entra ID to natively plug into the OS and provide the service to other apps to provide a more secure login process. WAM offers the following benefits:

- **Feature support**: Apps can access OS-level and service-level capabilities, including Windows Hello, conditional access policies, and FIDO keys.
- **Streamlined single sign-on**: Apps can use the built-in account picker, allowing the user to select an existing account instead of repeatedly entering the same credentials.
- **Enhanced security**: Bug fixes and enhancements ship with Windows.
- **Token protection**: Refresh tokens are device-bound, and apps can acquire device-bound access tokens.

Interactive brokered authentication enables the application for all operations allowed by the interactive login credentials. Personal Microsoft accounts and work or school accounts are supported. If a supported version of Windows is used, the default browser-based UI is replaced with a smoother authentication experience, similar to Windows built-in apps.

### Enable applications for interactive brokered authentication

Perform the following steps to enable the application to authenticate through the interactive broker flow.

1. On the [Azure portal](https://portal.azure.com), navigate to **Microsoft Entra ID** and select **App registrations** on the left-hand menu.
1. Select the registration for your app, then select **Authentication**.
1. Add the WAM redirect URI to your app registration via a platform configuration:
1. Under **Platform configurations**, select **+ Add a platform**.
1. Under **Configure platforms**, select the tile for your application type (platform) to configure its settings, such as **mobile and desktop applications**.
1. In **Custom redirect URIs**, enter the following WAM redirect URI:

```text
ms-appx-web://microsoft.aad.brokerplugin/{client_id}
```

The `{client_id}` placeholder must be replaced with the **Application (client) ID** listed on the **Overview** pane of the app registration.

1. Select **Configure**.

To learn more, see [Add a redirect URI to an app registration](/entra/identity-platform/quickstart-register-app#add-a-redirect-uri).

1. Back on the **Authentication** pane, under **Advanced settings**, select **Yes** for **Allow public client flows**.
1. Select **Save** to apply the changes.
1. To authorize the application for specific resources, navigate to the resource in question, select **API Permissions**, and enable **Microsoft Graph** and other resources you want to access. Microsoft Graph is usually enabled by default.

> [!IMPORTANT]
> You must also be the admin of your tenant to grant consent to your application when you sign in for the first time.

### Example using InteractiveBrowserCredential

The following example demonstrates using an <xref:Azure.Identity.InteractiveBrowserCredential> in a Windows Forms app to authenticate with the [`BlobServiceClient`](/dotnet/api/azure.storage.blobs.blobserviceclient):

:::code language="csharp" source="../snippets/authentication/additional-auth/interactive/InteractiveBrokeredAuth.cs" highlight="16-20":::

> [!NOTE]
> Visit the [Parent window handles](/entra/msal/dotnet/acquiring-tokens/desktop-mobile/wam#parent-window-handles) and [Retrieve a window handle](/windows/apps/develop/ui-input/retrieve-hwnd) articles for more information about retrieving window handles.

For the code to run successfully, your user account must be assigned an Azure role on the storage account that allows access to blob containers such as **Storage Account Data Contributor**. If an app is specified, it must have API permissions set for **user_impersonation Access Azure Storage** (step 6 in the previous section). This API permission allows the app to access Azure storage on behalf of the signed-in user after consent is granted during sign-in.

The following screenshot shows the user sign-in experience:

:::image type="content" source="../media/web-account-manager-sign-in-account-picker.png" alt-text="A screenshot that shows the sign-in experience when using the interactive browser broker credential to authenticate a user." :::

### Authenticate the default system account via WAM

Many people always sign in to Windows with the same user account and, therefore, only ever want to authenticate using that account. WAM and `InteractiveBrowserCredential` also support a silent login process that automatically uses a default account so the user doesn't have to repeatedly select it.

The following example shows how to enable sign-in with the default system account:

:::code language="csharp" source="../snippets/authentication/additional-auth/interactive/SilentBrokeredAuth.cs" highlight="16-24":::

Once you opt in to this behavior, the credential attempts to sign in by asking the underlying Microsoft Authentication Library (MSAL) to perform the sign-in for the default system account. If the sign-in fails, the credential falls back to displaying the account picker dialog, from which the user can select the appropriate account.

## Device code authentication

This method interactively authenticates a user on devices with limited UI (typically devices without a keyboard):
Expand Down
176 changes: 176 additions & 0 deletions docs/azure/sdk/authentication/local-development-broker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
title: Authenticate .NET apps to Azure using brokered authentication.
description: Learn how to authenticate your app to Azure services when using the Azure SDK for .NET during local development using brokered authentication.
ms.topic: how-to
ms.custom: devx-track-dotnet, engagement-fy23, devx-track-azurecli
ms.date: 08/20/2025
zone_pivot_groups: operating-systems-set-one
---

# Authenticate .NET apps to Azure services during local development using brokered authentication

Brokered authentication collects user credentials using the system authentication broker to authenticate an app with <xref:Azure.Identity.InteractiveBrowserCredential>. A system authentication broker is an app running on a user's machine that manages the authentication handshakes and token maintenance for all connected accounts.

Brokered authentication offers the following benefits:

- **Enables Single Sign-On (SSO):** Enables apps to simplify how users authenticate with Microsoft Entra ID and protects Microsoft Entra ID refresh tokens from exfiltration and misuse.
- **Enhanced security:** Many security enhancements are delivered with the broker, without needing to update the app logic.
- **Enhanced feature support:** With the help of the broker, developers can access rich OS and service capabilities.
- **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.
- **Token Protection:** Ensures that the refresh tokens are device bound and enables apps to acquire device bound access tokens. See [Token Protection](/azure/active-directory/conditional-access/concept-token-protection).

:::zone target="docs" pivot="os-windows"

Windows provides an authentication broker called [Web Account Manager (WAM)](/entra/msal/dotnet/acquiring-tokens/desktop-mobile/wam). WAM enables identity providers such as Microsoft Entra ID to natively plug into the OS and provide secure login services to apps. Brokered authentication enables the app for all operations allowed by the interactive login credentials.

Personal Microsoft accounts and work or school accounts are supported. On supported Windows versions, the default browser-based UI is replaced with a smoother authentication experience, similar to built-in Windows apps.

:::zone-end

:::zone target="docs" pivot="os-macos"

macOS doesn't natively include a built-in authentication broker. Brokered authentication is supported via the `Azure.Identity.Broker` library, which uses platform-specific mechanisms and may integrate with apps like Microsoft Company Portal when devices are managed. For more information, see [Microsoft Enterprise SSO plug-in for Apple devices](/entra/identity-platform/apple-sso-plugin).

:::zone-end

:::zone target="docs" pivot="os-linux"

Linux uses [Microsoft single sign-on for Linux](/entra/identity/devices/sso-linux) as its authentication broker.

:::zone-end

## Configure the app for brokered authentication

To enable brokered authentication in your application, follow these steps:

1. In the [Azure portal](https://portal.azure.com), navigate to **Microsoft Entra ID** and select **App registrations** on the left-hand menu.
1. Select the registration for your app, then select **Authentication**.
1. Add the appropriate redirect URI to your app registration via a platform configuration:
1. Under **Platform configurations**, select **+ Add a platform**.
1. Under **Configure platforms**, select the tile for your application type (platform) to configure its settings, such as **mobile and desktop applications**.
1. In **Custom redirect URIs**, enter the following redirect URI for your platform:

| Platform | Redirect URI |
|-------------|-----------------------------------------------------------------------------------------------------------------------|
| Windows 10+ or WSL | `ms-appx-web://Microsoft.AAD.BrokerPlugin/{your_client_id}` |
| macOS | `msauth.com.msauth.unsignedapp://auth` for unsigned apps<br>`msauth.{bundle_id}://auth` for signed apps |
| Linux | `https://login.microsoftonline.com/common/oauth2/nativeclient` |

Replace `{your_client_id}` or `{bundle_id}` with the **Application (client) ID** from the app registration's **Overview** pane.

1. Select **Configure**.

To learn more, see [Add a redirect URI to an app registration](/entra/identity-platform/quickstart-register-app#add-a-redirect-uri).

1. Back on the **Authentication** pane, under **Advanced settings**, select **Yes** for **Allow public client flows**.
1. Select **Save** to apply the changes.
1. To authorize the application for specific resources, navigate to the resource in question, select **API Permissions**, and enable **Microsoft Graph** and other resources you want to access.

> [!IMPORTANT]
> You must also be the admin of your tenant to grant consent to your application when you sign in for the first time.

## Assign roles

To run your app code successfully with brokered authentication, grant your user account permissions using [Azure role-based access control (RBAC)](/azure/role-based-access-control/overview). Assign an appropriate role to your user account for the relevant Azure service. For example:

- **Azure Blob Storage**: Assign the **Storage Account Data Contributor** role.
- **Azure Key Vault**: Assign the **Key Vault Secrets Officer** role.

If an app is specified, it must have API permissions set for **user_impersonation Access Azure Storage** (step 6 in the previous section). This API permission allows the app to access Azure storage on behalf of the signed-in user after consent is granted during sign-in.

## Implement the code

:::zone target="docs" pivot="os-windows, os-macos"

The Azure Identity library supports brokered authentication using <xref:Azure.Identity.InteractiveBrowserCredential>. For example, to use `InteractiveBrowserCredential` in a MAUI app to authenticate to Azure Key Vault with the [`SecretClient`](/dotnet/api/azure.security.keyvault.secrets.secretclient), follow these steps:

:::zone-end

:::zone target="docs" pivot="os-linux"

The Azure Identity library provide interactive brokered authentication using <xref:Azure.Identity.InteractiveBrowserCredential>. For example, to use `InteractiveBrowserCredential` in a console app to authenticate to Azure Key Vault with the [`SecretClient`](/dotnet/api/azure.security.keyvault.secrets.secretclient), follow these steps:

:::zone-end

:::zone target="docs" pivot="os-windows"

1. Install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) and [Azure.Identity.Broker](https://www.nuget.org/packages/Azure.Identity.Broker) packages.

```dotnetcli
dotnet add package Azure.Identity
dotnet add package Azure.Identity.Broker
```

1. Get a reference to the parent window on top of which the account picker dialog should appear.
1. Create an instance of <xref:Azure.Identity.InteractiveBrowserCredential> using <xref:Azure.Identity.Broker.InteractiveBrowserCredentialBrokerOptions>.

:::code language="csharp" source="../snippets/authentication/brokered/maui-app/MainPage.xaml.cs" id="snippet_brokered_windows" highlight="6-13":::

:::zone-end

:::zone target="docs" pivot="os-macos"

1. Install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) and [Azure.Identity.Broker](https://www.nuget.org/packages/Azure.Identity.Broker) packages.

```dotnetcli
dotnet add package Azure.Identity
dotnet add package Azure.Identity.Broker
```

> [!NOTE]
> macOS support exists in `Azure.Identity.Broker` versions 1.3.0 and later.

2. Get a reference to the parent window on top of which the account picker dialog should appear.
3. Create an instance of <xref:Azure.Identity.InteractiveBrowserCredential> using <xref:Azure.Identity.Broker.InteractiveBrowserCredentialBrokerOptions>.

:::code language="csharp" source="../snippets/authentication/brokered/maui-app/MainPage.xaml.cs" id="snippet_brokered_macos" highlight="6-13":::

:::zone-end

:::zone target="docs" pivot="os-linux"

1. Install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) and [Azure.Identity.Broker](https://www.nuget.org/packages/Azure.Identity.Broker) packages.

```dotnetcli
dotnet add package Azure.Identity
dotnet add package Azure.Identity.Broker
```

> [!NOTE]
> Linux support exists in `Azure.Identity.Broker` versions 1.3.0 and later.

2. Get a reference to the parent window on top of which the account picker dialog should appear.
3. Create an instance of <xref:Azure.Identity.InteractiveBrowserCredential> using <xref:Azure.Identity.Broker.InteractiveBrowserCredentialBrokerOptions>.

:::code language="csharp" source="../snippets/authentication/brokered/console-app/Program.cs" id="snippet_brokered_linux" highlight="15-21":::

:::zone-end

> [!TIP]
> View the [complete sample app code](https://github.com/dotnet/docs/tree/main/docs/azure/sdk/snippets/authentication/brokered) in the .NET docs GitHub repository.

In the preceding example, property <xref:Azure.Identity.Broker.InteractiveBrowserCredentialBrokerOptions.UseDefaultBrokerAccount%2A> is set to `true`, which opts into a silent, brokered authentication flow with the default system account. In this way, the user doesn't have to repeatedly select the same account. If silent, brokered authentication fails, or `UseDefaultBrokerAccount` is set to `false`, `InteractiveBrowserCredential` falls back to interactive, brokered authentication.

:::zone target="docs" pivot="os-windows"

The following screenshot shows the alternative interactive, brokered authentication experience:

:::image type="content" source="../media/broker-web-account-manager-account-picker.png" alt-text="A screenshot that shows the Windows sign-in experience when using a broker-enabled InteractiveBrowserCredential instance to authenticate a user.":::

:::zone-end

:::zone target="docs" pivot="os-macos"

The following screenshot shows the alternative interactive, brokered authentication experience:

:::image type="content" source="../media/broker-macos-account-picker.png" alt-text="A screenshot that shows the macOS sign-in experience when using a broker-enabled InteractiveBrowserCredential instance to authenticate a user.":::

:::zone-end

:::zone target="docs" pivot="os-linux"

The following video shows the alternative interactive, brokered authentication experience:

:::image type="content" source="../media/broker-linux-login.gif" alt-text="An animated gif that shows the Linux sign-in experience when using a broker-enabled InteractiveBrowserCredential instance to authenticate a user.":::

:::zone-end
Binary file added docs/azure/sdk/media/broker-linux-login.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
<!-- ASP.NET Core packages -->
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageVersion Include="Microsoft.Maui.Controls" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ private void testInteractiveBrokeredAuth_Click(object sender, EventArgs e)
new InteractiveBrowserCredentialBrokerOptions(windowHandle));

// To authenticate and authorize with an Entra ID app registration, substitute the
// <app_id> and <tenant_id> placeholders with the values for your app and tenant.
// <your-tenant-id> and <your-client-id> placeholders with the values for your app and tenant.
// var credential = new InteractiveBrowserCredential(
// new InteractiveBrowserCredentialBrokerOptions(windowHandle)
// {
// TenantId = "your-tenant-id",
// ClientId = "your-client-id"
// TenantId = "<your-tenant-id>",
// ClientId = "<your-client-id>"
// }
// );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ private void testSilentBrokeredAuth_Click(object sender, EventArgs e)
});

// To authenticate and authorize with an app, substitute the
// <app_id> and <tenant_id> placeholders with the values for your app and tenant.
// <your-tenant-id> and <your-client-id> placeholders with the values for your app and tenant.
// var credential = new InteractiveBrowserCredential(
// new InteractiveBrowserCredentialBrokerOptions(windowHandle)
// {
// TenantId = "your-tenant-id",
// ClientId = "your-client-id"
// TenantId = "<your-tenant-id>",
// ClientId = "<your-client-id>"
// }
// );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ProjectUISubcaption>Linux</ProjectUISubcaption>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Identity.Broker" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
</ItemGroup>
</Project>
Loading