Skip to content

Commit b0cb813

Browse files
Copilotwadepickett
andauthored
Rewrite azure-ad-b2c.md as slim bridge page (#36922)
* Initial plan * Rewrite azure-ad-b2c.md as slim bridge page and delete sample/static files Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/5d260fcb-c1d8-48e7-8ecc-dbadb776f49f * Fix metadata ordering: title first, then alphabetical Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/5d260fcb-c1d8-48e7-8ecc-dbadb776f49f * Remove .nuget/nuget.exe and add .nuget/ to .gitignore Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/5d260fcb-c1d8-48e7-8ecc-dbadb776f49f * Revert .gitignore to original state Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/AspNetCore.Docs/sessions/7f758f5e-bc07-4683-bd1c-32d89edd6e6b * Apply suggestion from @wadepickett * Apply suggestion from @wadepickett * Apply suggestion from @wadepickett * Remove MFA link from Azure AD B2C documentation Removed dupe link to multi-factor authentication documentation. * Apply suggestion from @wadepickett * Include migration section for Azure AD B2C Added migration guidance for Azure AD B2C to Entra External ID. * Apply suggestion from @wadepickett * Apply suggestions from code review Co-authored-by: Wade Pickett <wpickett@microsoft.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com> Co-authored-by: Wade Pickett <wpickett@microsoft.com>
1 parent 9b0240a commit b0cb813

43 files changed

Lines changed: 33 additions & 74437 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 33 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,60 @@
11
---
22
title: Cloud authentication with Azure Active Directory B2C in ASP.NET Core
3-
author: guardrex
3+
ai-usage: ai-assisted
4+
author: wadepickett
45
description: Discover how to set up Azure Active Directory B2C authentication with ASP.NET Core.
56
ms.author: wpickett
67
ms.custom: "devx-track-csharp, mvc"
7-
ms.date: 02/27/2026
8+
ms.date: 03/25/2026
89
uid: security/authentication/azure-ad-b2c
910
---
1011
# Cloud authentication with Azure Active Directory B2C in ASP.NET Core
1112

12-
By [Damien Bod](https://github.com/damienbod)
13-
1413
[!INCLUDE[](~/includes/azure-active-directory-b2c-eol-support-notice.md)]
1514

16-
[Azure Active Directory B2C](/azure/active-directory-b2c/active-directory-b2c-overview) (Azure AD B2C) is a cloud identity management solution for web and mobile apps. The service provides authentication for apps hosted in the cloud and on-premises. Authentication types include individual accounts, social network accounts, and federated enterprise accounts. Additionally, Azure AD B2C can provide multi-factor authentication with minimal configuration.
17-
18-
> [!TIP]
19-
> Microsoft Entra ID, Microsoft Entra External ID and Azure AD B2C are separate product offerings. An Entra ID tenant generally represents an organization, while an Azure AD B2C tenant or a Microsoft Entra External ID tenant can represent a collection of identities to be used with relying party applications. To learn more, see [Azure AD B2C: Frequently asked questions (FAQ)](/azure/active-directory-b2c/active-directory-b2c-faqs).
20-
21-
> [!TIP]
22-
> [Microsoft Entra External ID for customers](/azure/active-directory/external-identities/customers/overview-customers-ciam) is Microsoft’s new customer identity and access management (CIAM) solution.
23-
24-
In this tutorial, you'll learn how to configure an ASP.NET Core app for authentication with Azure AD B2C.
25-
26-
## Prerequisites
27-
28-
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
29-
* .NET SDK. [Install the latest .NET SDK](https://dotnet.microsoft.com/download/dotnet) for your platform.
30-
31-
## Preparation
32-
33-
1. [Create an Azure Active Directory B2C tenant](/azure/active-directory-b2c/tutorial-create-tenant).
34-
1. Create a new ASP.NET Core Razor pages app:
35-
36-
```dotnetcli
37-
dotnet new razor -o azure-ad-b2c
38-
```
39-
40-
The previous command creates a Razor pages app in a directory named *azure-ad-b2c*.
41-
42-
> [!TIP]
43-
> You may prefer to [use Visual Studio to create your app](/visualstudio/ide/quickstart-aspnet-core).
44-
45-
1. [Create a web app registration in the tenant](/azure/active-directory-b2c/tutorial-register-applications#register-a-web-application). For **Redirect URI**, use `https://localhost:5001/signin-oidc`. Replace `5001` with the port used by your app when using Visual Studio generated ports.
46-
47-
## Modify the app
48-
49-
1. Add the `Microsoft.Identity.Web` and `Microsoft.Identity.Web.UI` packages to the project. If you're using Visual Studio, you can use [NuGet Package Manager](/nuget/consume-packages/install-use-packages-visual-studio).
50-
51-
```dotnetcli
52-
dotnet add package Microsoft.Identity.Web
53-
dotnet add package Microsoft.Identity.Web.UI
54-
```
55-
56-
In the preceding:
57-
58-
* `Microsoft.Identity.Web` includes the basic set of dependencies for authenticating with the Microsoft identity platform.
59-
* `Microsoft.Identity.Web.UI` includes UI functionality encapsulated in an area named `MicrosoftIdentity`.
60-
61-
1. Add an `AzureADB2C` object to `appsettings.json`.
62-
63-
> [!NOTE]
64-
> When using Azure B2C user flows, you need to set the **Instance** and the PolicyId of the type of flow.
65-
66-
:::code language="json" source="azure-ad-b2c/sample/appsettings-b2c-userflow.json" highlight="2-17":::
67-
68-
* For **Domain**, use the domain of your Azure AD B2C tenant.
69-
* For **ClientId**, use the **Application (client) ID** from the app registration you created in your tenant.
70-
* For **Instance**, use the domain of your Azure AD B2C tenant.
71-
* For **TenantId**, use the **Tenant ID** from your Azure AD B2C tenant. In the Azure portal, search for and select **Microsoft Entra ID**. In the **Overview**, copy the **Tenant ID**.
72-
* For **SignUpSignInPolicyId**, use the user flow policy defined in the Azure B2C tenant
73-
* Use either the **ClientSecret** or the **ClientCertificates** configuration. ClientCertificates are recommended.
74-
* Leave all other values as they are.
75-
76-
1. In *Pages/Shared*, create a file named `_LoginPartial.cshtml`. Include the following code:
77-
78-
:::code language="razor" source="azure-ad-b2c/sample/Pages/Shared/_LoginPartial.cshtml":::
79-
80-
The preceding code:
81-
82-
* Checks if the user is authenticated.
83-
* Renders a **Sign out** or **Sign in** link as appropriate.
84-
* The link points to an action method on the `Account` controller in the `MicrosoftIdentity` area.
85-
86-
1. In *Pages/Shared/_Layout.cshtml*, add the highlighted line within the `<header>` element:
15+
## Recommended path for new projects
8716

88-
:::code language="razor" source="azure-ad-b2c/sample/Pages/Shared/_Layout.cshtml" range="12-33" highlight="18":::
89-
90-
Adding `<partial name="_LoginPartial" />` renders the `_LoginPartial.cshtml` partial view in every page request that uses this layout.
17+
[Microsoft Entra External ID for customers](/entra/external-id/customers/overview-customers-ciam) is the recommended customer identity and access management (CIAM) solution for new ASP.NET Core applications, replacing Azure AD B2C with the latest identity platform features.
9118

92-
1. In *Program.cs*, make the following changes:
19+
To get started with a new project, see [Sign in users in a sample ASP.NET Core web app](/entra/external-id/customers/sample-web-app-dotnet-sign-in).
9320

94-
1. Add the following `using` directives:
95-
96-
:::code language="csharp" source="azure-ad-b2c/sample/Program.cs" id="snippet_NewUsings":::
21+
## Migrate from Azure AD B2C to Entra External ID
9722

98-
The preceding code resolves references used in the next steps.
23+
To migrate an existing Azure AD B2C application to the newer platform, see [Plan and execute a migration to Microsoft Entra External ID](/entra/external-id/customers/migrate-to-external-id).
9924

100-
1. Update the `builder.Services` lines with the following code:
101-
102-
:::code language="csharp" source="azure-ad-b2c/sample/Program.cs" id="snippet_builderservices":::
25+
For detailed guidance on moving user accounts, including password migration strategies, see [Migrating users to Microsoft Entra External ID](/entra/external-id/customers/how-to-migrate-users).
10326

104-
In the preceding code:
27+
## Guidance for existing Azure AD B2C projects
10528

106-
* Calls to the `AddAuthentication` and `AddMicrosoftIdentityWebApp` methods configure the app to use OpenID Connect, specifically configured for the Microsoft identity platform.
107-
* `AddAuthorization` initializes ASP.NET Core authorization.
108-
* The `AddRazorPages` call configures the app so anonymous browsers can view the Index page. All other requests require authentication.
109-
* `AddMvcOptions` and `AddMicrosoftIdentityUI` add the required UI components for redirecting to/from Azure AD B2C.
110-
111-
1. Update the highlighted line to the `Configure` method:
112-
113-
:::code language="csharp" source="azure-ad-b2c/sample/Program.cs" id="snippet_app":::
29+
Azure AD B2C remains supported for existing applications. Authoritative setup and configuration guidance is maintained in the Azure AD B2C documentation. The following articles cover the topics that ASP.NET Core developers typically need:
11430

115-
The preceding code enables authentication in ASP.NET Core.
31+
| Topic | Article |
32+
|---|---|
33+
| Create a tenant | [Tutorial: Create an Azure AD B2C tenant](/azure/active-directory-b2c/tutorial-create-tenant) |
34+
| Register a web application | [Tutorial: Register a web application in Azure AD B2C](/azure/active-directory-b2c/tutorial-register-applications) |
35+
| Configure authentication in an ASP.NET Core app | [Configure authentication in a sample ASP.NET Core web app](/azure/active-directory-b2c/configure-authentication-sample-web-app) |
36+
| Enable multi-factor authentication | [Enable MFA in Azure AD B2C](/azure/active-directory-b2c/multi-factor-authentication) |
11637

117-
## Run the app
38+
## ASP.NET Core integration checklist
11839

119-
> [!NOTE]
120-
> Use the profile which matches the Azure App registration **Redirect URIs**.
121-
1. Run the app.
122-
123-
```dotnetcli
124-
dotnet run --launch-profile https
125-
```
40+
After completing identity provider setup using the Entra or Azure AD B2C documentation, complete the following ASP.NET Core-specific steps:
12641

127-
1. Browse to the app's secure endpoint, for example, `https://localhost:5001/`.
128-
* The Index page renders with no authentication challenge.
129-
* The header includes a **Sign in** link because you're not authenticated.
42+
1. **Install NuGet packages:** Add the [`Microsoft.Identity.Web`](https://www.nuget.org/packages/Microsoft.Identity.Web) and [`Microsoft.Identity.Web.UI`](https://www.nuget.org/packages/Microsoft.Identity.Web.UI) packages:
13043

131-
1. Select the **Privacy** link.
132-
* The browser is redirected to your tenant's configured authentication method.
133-
* After signing in, the header displays a welcome message and a **Sign out** link.
44+
```dotnetcli
45+
dotnet add package Microsoft.Identity.Web
46+
dotnet add package Microsoft.Identity.Web.UI
47+
```
13448

135-
## Next steps
49+
1. **Configure services in `Program.cs`:** Call `AddMicrosoftIdentityWebApp` to configure OpenID Connect authentication for the Microsoft identity platform, and call `AddMicrosoftIdentityUI` to add the required sign-in/sign-out UI components. For the full API reference, see the [Microsoft Identity Web documentation](https://github.com/AzureAD/microsoft-identity-web/wiki).
13650

137-
In this tutorial, you learned how to configure an ASP.NET Core app for authentication with Azure AD B2C.
51+
1. **Add configuration:** Add the `AzureADB2C` section in `appsettings.json` with values that match your tenant and app registration. See [Configure authentication in a sample ASP.NET Core web app](/azure/active-directory-b2c/configure-authentication-sample-web-app) for the complete schema and sample.
13852

139-
Now that the ASP.NET Core app is configured to use Azure AD B2C for authentication, the [Authorize attribute](xref:security/authorization/simple) can be used to secure your app. Continue developing your app by learning to:
53+
## Additional resources
14054

141-
* [Customize the Azure AD B2C user interface](/azure/active-directory-b2c/active-directory-b2c-reference-ui-customization).
142-
* [Configure password complexity requirements](/azure/active-directory-b2c/active-directory-b2c-reference-password-complexity).
143-
* [Enable multi-factor authentication](/azure/active-directory-b2c/active-directory-b2c-reference-mfa).
144-
* Configure additional identity providers, such as [Microsoft](/azure/active-directory-b2c/active-directory-b2c-setup-msa-app), [Facebook](/azure/active-directory-b2c/active-directory-b2c-setup-fb-app), [Google](/azure/active-directory-b2c/active-directory-b2c-setup-goog-app), [Amazon](/azure/active-directory-b2c/active-directory-b2c-setup-amzn-app), [Twitter](/azure/active-directory-b2c/active-directory-b2c-setup-twitter-app), and others.
145-
* [Use the Microsoft Graph API](/azure/active-directory-b2c/microsoft-graph-operations) to retrieve additional user information, such as group membership, from the Azure AD B2C tenant.
146-
* [How to secure a Web API built with ASP.NET Core using the Azure AD B2C](https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/4-WebApp-your-API/4-2-B2C).
147-
* [Tutorial: Grant access to an ASP.NET web API using Azure Active Directory B2C](/azure/active-directory-b2c/tutorial-web-api-dotnet).
55+
* [Microsoft Entra External ID for customers overview](/entra/external-id/customers/overview-customers-ciam)
56+
* [Azure AD B2C documentation](/azure/active-directory-b2c/)
57+
* [Customize the Azure AD B2C user interface](/azure/active-directory-b2c/customize-ui)
58+
* [Configure password complexity in Azure AD B2C](/azure/active-directory-b2c/password-complexity)
59+
* [Microsoft Graph API with Azure AD B2C](/azure/active-directory-b2c/microsoft-graph-operations)
60+
* <xref:security/authentication/index>
Binary file not shown.
-36.8 KB
Binary file not shown.
Binary file not shown.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Error.cshtml

Lines changed: 0 additions & 26 deletions
This file was deleted.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Error.cshtml.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Index.cshtml

Lines changed: 0 additions & 10 deletions
This file was deleted.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Index.cshtml.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Privacy.cshtml

Lines changed: 0 additions & 8 deletions
This file was deleted.

aspnetcore/security/authentication/azure-ad-b2c/sample/Pages/Privacy.cshtml.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)