Microsoft Entra ID Integration with .NET 8 ASP.NET Core Application

Introduction

Microsoft Entra ID is a cloud-based service designed for identity and access management. It empowers your employees to seamlessly access external resources while also facilitating secure access to internal applications, including those on your corporate intranet and any custom cloud applications developed specifically for your organization.

Pre-requests

  • Microsoft Entra ID tenant
  • Visual Studio 2022 with .NET 8

Microsoft Entra ID integration with ASP.NET Core application

Step 1. Open Visual Studio and create a new ASP.NET Core web application using the MVC template.

Step 2. Enter a project name. In my case, I have named it MSEntraID-DNET8 and clicked on next.

Project name

Step 3. Install the required components

Let’s install the dotnet Identity tool. From the below image click on the next.

Components

In the next wizard, select your MS Entra ID tenant and click on Create new.

Register app

Enter the application name, and click on register. This will register the application in Microsoft Entra ID with all necessary configurations for Identity Management with Open ID Connect.

Register app

App created

Select your app and click on next to add additional settings. Select Add Microsoft Graph permissions with the scope user.read and click on Next.

The next step will generate a Client Secret and use Secret.json to save the secret. For production, use Key Vault to save the secret.

Client secret

Finally, click on finish. This will install all necessary packages in our application to integrate the Microsoft Entra ID Identity Management.

Service dependencies

Service dependencies are installed successfully.

Step 4. Run and test the application

Application

I logged in successfully using my Outlook email address.

Login to Azure portal - > Microsoft Entra ID- > Select the registered app -> Click on Authentication under Manage Blade.

Add the Redirect URI once your application is deployed to a different environment.

Redirect URL

Summary

In this article, we explore the seamless integration of Microsoft Entra ID with an ASP.NET Core application, leveraging the powerful capabilities of .NET 8. The process begins with the creation of a dedicated app in Microsoft Entra ID, followed by the steps of registering it for integrated Microsoft Identity management within the ASP.NET Core application. This comprehensive guide walks through the essential steps. This integration ensures a robust and streamlined authentication process, laying the foundation for a secure and efficient application.