Your apps may implement authentication quite easily with the help of Microsoft’s ASP.NET framework. Hardly little has to be done to create a standard web application. You need to do little more than tick a few boxes to proceed.

You may not be aware, though, that ASP.NET user authentication may be added to console applications.

Thankfully, the hidden magic is mostly gone with.NET Core. All the components needed for authentication are available to you, and you are free to reuse them as necessary.

Making two projects—a console application and a web application—is the simplest method to do this. Make sure ASP.NET authentication is turned on in the web application before you begin.

All that is left to do is transfer some settings from the web application to our console application.

We must first include a few NuGet packages in our console application. References will be required for:

  • Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.UI

You must first construct your NuGet packages before creating the ApplicationUser class and the Entity Framework database context.

After getting your Entity Framework stuff set up, all that is really left to configure is your .NET Core DI.

Now that everything has been set up, we can use our console application to access ASP.NET Identity data just as we would in a web application. A example authentication service with numerous typical user-related features is shown below.

Leave a comment

Your email address will not be published.