Skip to content
Mate Gelei-Szego
Mate Gelei-Szego

Making huge cloud deployments a little more effective.

  • Home
  • About me
Mate Gelei-Szego

Making huge cloud deployments a little more effective.

Quickstart – Azure AD B2C authentication in ASP.NET Core MVC

Posted on November 28, 2023April 23, 2025

There’s a lot of identity providers for ASP.NET. One of the easiest (and cheapest, if you’re under 50k MAU) option is to use Azure AD B2C. Here’s the quickest was to get up and running with an ASP.NET Core MVC app and Azure AD B2C identity.

Create a B2C directory

This is different from your regular Azure AD / Entra directory. Log in to the Azure Portal, click “Create a resource”, and find Azure Active Directory B2C.

Here, click “Create new tenant”, and fill in its details.

Tenant settings

Next, open the newly created tenant and go to user flows. Create 3 new flows: signup/signin, edit profile and reset password. WHen being asked for a version, select “recommended”.

  • Name: we will reference this (along with the domain entered above) in our app settings. If you enter SignUpSignIn, the final name would be B2C_1_SignUpSignIn
  • Identity Providers: you can set up different identity providers, with email being the default one. Let’s keep it for now.
  • MFA: pick whatever you’d like, but keep in mind that some of these settings would generate extra charges
  • User attributes: here you can specify what pieces of data you’d like the user to provide, and what would be passed to your app in the token responses.

Create application

On the B2C tenant portal, create a new app registration. Provide the name and the redirect URI, which in our case would be something like https://localhost:5001/signin-oidc.

Make sure you enable implicit flows.

Configure the ASP.NET Core MVC app

Create your MVC app like this:

Add the following Nuget packages:

dotnet add package Microsoft.Identity.Web
dotnet add package Microsoft.Identity.Web.UI

Now open Program.cs and add the authentication middleware: app.UseAuthentication();

After that, open your appsettings.json and make the following changes:

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email

Post navigation

Previous post
Next post

Mate Gelei-Szego

Experienced cloud engineer with a background in software development, service management and finance.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • On case-sensitive file systems
  • Unlocking Ubuntu LUKS2 encryption automatically at boot
  • Install RSAT via Powershell
  • Azure DevOps – build pipeline billing extravaganza
  • Quickstart – Azure AD B2C authentication in ASP.NET Core MVC

Categories

  • Azure
  • C# / .NET
  • Note to self
  • Random
©2025 Mate Gelei-Szego | WordPress Theme by SuperbThemes