Integrating an ASP.Net App with Azure AD – Easy as 123

I have been working with Microsoft.AspNetCore.Authentication.AzureAD.UI for authenticating with Azure AD. I noticed however that in a recent project it is now deprecated.

So I thought I’d spend some time learning the new way of integrating with Azure AD using the Microsoft Identity Platform. I was pleasantly surprised how easy it is.

Three Easy Steps

There are only 3 steps to creating a new MVC app that integrates with Azure AD

  1. Register the app in the Azure Portal
  2. Create a new MVC project with the Microsoft Identity Platform authentication type
  3. Copy the settings from the portal into the app and run

And that is it!

Step 1 – Register the App in Azure Portal

  • Go to https://portal.azure.com, then to App Registrations and click New registration
  • Enter the name you want to call it in Azure
  • In the Redirect URL enter https://localhost:44382/signin-oidc
    This will redirect back to your website when you run it locally
    In production this will be your websites URI – you can have multiple URI’s.
  • Click Register
New App registration settings in Azure Portal

Make note of the Client and Tenant ID’s

You will need both the client ID and tenant ID to put into your web application (see below).

client and tenant IDs in Azure Portal

Step 2 – Create a new MVC Project

Now this is where things get really easy.

Create a new ASP.NET Core web App.

New Visual Studio ASP.NET Core Web App

On the third page set the Authentication Type to Microsoft Identity platform.

Authentication Type in new Visual Studio Project

Choosing Microsoft Identity platform as the authentication type will include the packages for your integration with Azure AD.

Click create.

Step 3 – Copy the Portal Settings Into the Project

When the project opens it opens the appsettings.json.

Add your domain
Get your TenantId and ClientId from the App Registration in the portal (see image above) and paste into the appsettings

Done!

And that is how easy it is, simply run the application, and log in.

New ASP.Net Web App Home page

Leave a Reply

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