ASP.NET Core Authentication – Session 59

ASP.NET Core Authentication

During this session, we are going to discuss ASP.NET Core Authentication and for this purpose, we use Entity Framework Core Identity. The process of determining a user’s identification is called authentication. The system links a set of identifying credentials to an incoming request. The submitted credentials are compared to those stored in a database on a local operating system or within an authentication server with information about the authorized user. During this tutorial we used Microsoft.AspNetCore.Identity.EntityFrameworkCore package to manage authentication, authorization, and user management.

What is Authentication?

The process of determining a user’s identification is called authentication. The system links a set of identifying credentials to an incoming request. The submitted credentials are compared to those stored in a database on a local operating system or within an authentication server with information about the authorized user.

Entity Framework Core Identity

To implement authentication, we need to use the Entity Framework Core Identity package and we need to install it through NuGet Package Manager. We discussed NuGet Packages during Session 45 and talked about upgrading the packages in Session 48.

The package that we need to install is Microsoft.AspNetCore.Identity.EntityFrameworkCore. Just bear in mind we need to install the version which is compatible with the installed EF Core version.

EF Core Identity Entities

To add the EF Core Identity entities, first, we need to modify our web app DB Context as you can see below.

As you can see, we inherited the DbContext class from IdentityDbContext and we added the base.OnModelCreating(modelBuilder) to the OnModelCreating method.

Then, we need to add Identity as a service in the Startup Class and ConfigureServices method.

Moreover, to add authentication to our web app we need to add Authentication middleware to Startup Class and Configure method.

Now, we can add the EF Core Identity Entities to our database by running Add-Migration and Update-Database commands inside the Package Manager Console. If you need more information about the Package Manager Console watch Session 46 where we explained it in detail.

If you need more details, watch this session video. Also, to be updated about our coming sessions, follow us on Instagram, Facebook, Telegram, or YouTube. Moreover, you can have access to the list of all sessions HERE and you can download this session source code from our GitHub.

You can download this Session Slides form HERE.

0.00 avg. rating (0% score) - 0 votes

Tags

0 0 votes
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments