-
Notifications
You must be signed in to change notification settings - Fork 6k
Extracted broker auth into new doc #48046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
2d2853f
Extracted broker auth into new doc
alexwolfmsft 162869a
fix metadata
alexwolfmsft 835f844
fix toc
alexwolfmsft 5d910e0
Apply suggestions from code review
alexwolfmsft 8fc22b8
Apply suggestions from code review
alexwolfmsft df06fe4
Apply suggestions from code review
alexwolfmsft 04ba363
Apply suggestions from code review
alexwolfmsft fdc226f
temp
alexwolfmsft f85473b
temp
alexwolfmsft 881a038
add additional OS
alexwolfmsft 2761f6c
fix zone pivots
alexwolfmsft ca6362f
Maui fixes
alexwolfmsft 61f5d96
fix code blocks
alexwolfmsft 4759332
refactor intro
alexwolfmsft d410988
fixes
alexwolfmsft ede3fa1
fixes
alexwolfmsft 5892f9d
fix code lines
alexwolfmsft 6e787bd
fixes
alexwolfmsft 893b0bc
changes
alexwolfmsft ec7ac00
fixes
alexwolfmsft 08ef06a
fixes
alexwolfmsft d7e79fc
fixes
alexwolfmsft e031539
fixes
alexwolfmsft dcab7fe
Apply suggestions from code review
alexwolfmsft 9b58686
Apply suggestions from code review
alexwolfmsft 7d3fd3a
PR Fixes
alexwolfmsft c836ded
update
alexwolfmsft 8ff30d2
code update
alexwolfmsft e0d208e
fix secrets
alexwolfmsft 9a606ac
remove secret
alexwolfmsft 420e5c9
fix compile
alexwolfmsft 8f95647
Apply suggestions from code review
alexwolfmsft b530aec
zone pivot change
alexwolfmsft d07511e
Apply suggestions from code review
alexwolfmsft c26c551
Apply suggestions from code review
alexwolfmsft 8896a4f
Merge
alexwolfmsft 5e09236
Merge branch 'new-broker-auth-doc' of https://github.com/alexwolfmsft…
alexwolfmsft 8fdcde2
fixes
alexwolfmsft 4db4afe
Apply suggestions from code review
alexwolfmsft f2af6cd
Add macOS screenshot
scottaddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
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 | ||
--- | ||
|
||
# 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 application 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. | ||
|
||
> [!NOTE] | ||
> 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](additional-methods.md#interactive-browser-authentication). | ||
|
||
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. | ||
|
||
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. | ||
|
||
## Configure the app for brokered authentication | ||
|
||
Complete the following steps to enable the application to authenticate through the broker flow: | ||
|
||
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 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} | ||
scottaddie marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
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. | ||
|
||
## Implement the code | ||
|
||
Complete the following steps in your .NET project: | ||
|
||
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. | ||
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> that accepts an instance of <xref:Azure.Identity.Broker.InteractiveBrowserCredentialBrokerOptions>. | ||
|
||
Consider the following sample code from a Windows Forms app that passes the credential to an instance of [BlobServiceClient](/dotnet/api/azure.storage.blobs.blobserviceclient): | ||
|
||
:::code language="csharp" source="../snippets/authentication/additional-auth/interactive/InteractiveBrokeredAuth.cs" highlight="16-20"::: | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
> [!NOTE] | ||
> For more information about retrieving window handles, see [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). | ||
|
||
For the code to run successfully, your user account must be assigned an Azure RBAC 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. | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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 a broker-enabled InteractiveBrowserCredential instance to authenticate a user." ::: | ||
|
||
### Authenticate the default system account via WAM | ||
alexwolfmsft marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.