ASP NET Core Identity tutorial from scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
they see spot 65 of asp.net core a tutorial in this video and in our upcoming videos in the series but let's cuz everything you need to know to effectively use asp.net core identity to implement security related features in your asp.net core application what is a spirit core identity well it's a built-in membership system it allows us to create read update and delete user counts account confirmation authentication and authorization password recovery two-factor authentication with SMS it also supports external login providers like Microsoft Facebook Google etc and much more well discuss implementing these features in our upcoming videos in the series now let's add support for asp.net core identity in our asp.net core application the first step is to make our application DB context class inherit from identity DB context instead of DB context let's bring in the required namespace by pressing control period known as this class is present in Microsoft a spinet core identity and a different core namespace if you're wondering why do we need to inherit from identity DB context class well that's because this class provides all the DB set properties needed to manage the identity tables in the underlying data store in our case Microsoft sequel server database will see all the tables that the asp.net core identity framework generates in each estimate for now let's go to the definition of this identity DB context class notice it inherits from identity DB context of identity user and identity role if we go to the definition on this class it inherits from another variation of identity DB context class as we go through the inheritance chain we'll see ultimately identity DB context class inherits from DB context class there we go this variation of identity user context class inherits from the DB context class this is the reason if our application DB context class is inheriting from dbcontext class we don't have to explicitly again inherit from the dbcontext class so this is a first step make your application dbcontext class derive from the identity DB context class next we need to add a speed or net core identity services to our application like many things in asp.net core we do this in the configure services method of the startup class which is present in this startup dot CS file to add identity services on this i service collection interface we call the aptly named add identity method notice from the intellisense this method has got two generic parameters T user and T roll where T user is a class and T roll is also a class so for the first parameter I'm going to pass the built-in identity user class as the argument and for the second parameter I'm going to pass identity role bringing the require namespace for these two classes which is Microsoft or SP net core dot identity if you're wondering why we're using this identity user class well to understand that first let's go to the definition of this class it inherits from identity user of string so let's go to the definition in this class as well notice we have properties like email password hash username etc it's between that core identity uses this built-in identity user class to manage the details of the registered users of our application for every property that you see in this class we have a corresponding column in the underlying users table we'll look at that in action in just a bit but if you take a look at this class this class has got only a limited set of properties what if you want to store additional information like the gender of the user and their City we don't have properties for gender and City within this built-in identity user class so what we can do is create a custom class and make that custom class inherit from this identity user class and within that custom class will include properties for all the additional data that we want to capture and then plug that custom class in instead of the built-in identity use a class but this is how to do this in our upcoming videos in this series similarly identity roll is also a built-in class provided by a speed or net core identity system and as the name implies it is used to manage user role information well this is adding new roles and implementing role based authorization in our upcoming videos now we want to use an LD framework or to retrieve user and role information from the underlying sequel server database using energy framework or we configure that by calling add entity framework stores method as a generic argument we specify our application DB context which is app dbcontext this is our second step adding a spirit net core identity services next add the authentication middleware to our applications request processing pipeline remember it is the configure method in the startup class that configures our applications request processing pipeline so in the configure method to add authentication malware call use authentication method so in our startup dot CS file in the configure method let's call use authentication extension method we want to be able to authenticate users before the request reaches the MVC malware so it's important we add the authentication middleware before the MVC middleware next we need to create a spirit and core identity tables in the underlined sequel server database for that we need to create a new migration before that let's build our solution to make sure we do not have any compilation errors there we go build succeeded next we want to add a new migration to add a new migration we use add migration command we discussed migrations in detail in our previous videos in the series so within Visual Studio in the package manager console window let's use add migration command and we need to specify a name let's call the migration adding identity and then press the Enter key we have an error the entity type identity user login of string requires a primary key to be defined if you are getting this error the most likely cause is within your application dbcontext class you are overriding on model creating method but you are not calling the base class on model creating method in this case the base class is identity DB context to fix this error all we need to do is call the base class on model creating method using the base keyword and then to this pass this incoming model builder object case of identity tables are mapped in on model creating method of this identity DB context class by calling base taught on model creating we are calling the on model heading method of this identity by context class so that keys are mapped and been no longer should have this error when we add the migration so let's try the migration command once again migration added notice the code in this migration creates several identity tables like asp net roles asp net users etc before we apply this migration to our database let's take a look at the tables that we have in the employee DB database at the moment we only have two tables employees and EF migration history now let's update our database with this migration for that we use update database command if we take a look at our employee DB database now notice we have several identity tables if we take a look at this SP net users table notice the columns in this table respond to the properties that we have in this built-in class identity user asp.net core uses this built-in class identity user and entity framework or two manage the data that we have in this SP net users table and this is exactly the reason why we have specified identity user as the generic argument for add identity method right here and the same is true even for identity role at the moment in this SP net users table we do not have columns to store additional information about the users like their gender our city in our upcoming videos in the series will discuss how to extend this built-in identity user class so we could store additional information about our registered users at this point our application is configured to use asp.net core identity we also created the required identity tables in the underlying sequel server database our next step is to register new users will discuss how to do that using asp.net core identity in our next video that's it in this video thank you for listening you [Music] you
Info
Channel: kudvenkat
Views: 181,748
Rating: undefined out of 5
Keywords: asp.net core identity step by step, asp.net core identity database schema, asp.net core identity database script, asp.net core identity example, asp.net core identity from scratch, asp.net core identity framework, asp.net core identity getting started, how to use asp.net core identity, asp.net core identity migration, asp.net core identity mvc, asp.net core identity overview, asp.net core identity sql server, asp.net core identity tutorial, asp.net core identity youtube
Id: egITMrwMOPU
Channel Id: undefined
Length: 10min 12sec (612 seconds)
Published: Mon Jun 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.