Claims based Authentication in dotnet core using Identity on user roles | .net identity Part 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys today I'm going to show you how to add claims to registered users who already have roles okay this is in continuation to uh the previous video of role-based Authentication um okay so we will be using the same program that we used for uh role-based authentication so here uh we already have users who have assigned roles so we will use them for claims so we have four users who have assigned roles one is admin and three are employee and we will be assigning them claims okay all right so let's begin so first thing we have to make is make some changes uh to the program.cs that we have in order to have claims so uh this was the program.cs created for roles now we are going to make some changes in it to have roles I just copy that and make it fast just above the Builder dot build okay so we will add build.services.ad region pieces raise the pages then build a DOT services.ad authorization option.ad policy and these are a few policies that we are assigning save it okay no more nuggets to add here so simple workarounds uh no more changes to the application DB context so let's move ahead and create an access claims controller empty controller which has let's name it as access claims okay copy the contents soon yes so what we used we used role manager we used user Manager application DB context won't be used here so I have not initialized it just called it maybe I'll use it in the future okay so role manager and user manager I'll in are initialized index and um index is is there to assign uh is there to access uh the view for anyone who is an um employee uh whoever is there I mean employee or admin whoever is there can access the in index okay and uh okay so uh assign claims will be assigned to will be accessible to admin only get and post after the claims has been done uh that is assigned to admin only and then we are assigning policy to the HRS page to the managers page to the anonymous no policies with Anonymous okay so HR manager and I guess there is another one customer we haven't used that one so I'm using it for HR and manager yeah customer I haven't used it because that's uh for outside users so let's begin okay I'll uh design the pages and I will show you so guys this is how we are adding blank pages to uh the HR only manager only Anonymous and then designing it after uh looking at the blank page manager's page is one more page and then I'll show you how it's working okay guys all the pages have been created now I'll show you one by one index okay so this one is for index it will have buttons uh it's accessible uh uh index is accessible ah to everyone No it should be only accessible to employees and uh admin one second yes to employees and admin roles with admin and employees are able to access all the open actions however the actions fixed with one role is accessible to that person only and the others are not okay so index is accessible to both admin and employee or other registered users are not able to access that okay and assign claims okay let me show you the view index has this view which has buttons and it's giving us access to other Pages it's taking us to other pages to a charge page to manager to assign claims to anonymous now um assigned claims will have admin access both get and post assign claims has a view of text boxes which asks for the email ID and the claims head that you want to assign it to and the claims value okay so you can have a look at this now the next claims done this is the confirmation page so just a confirmation message that the claim has been created the hr's page is only accessible to the HR so it only posts a message this page is accessible to the HR employees only manager has access to the manager uh claims employees and it has a message that this is accessible to management employees only then Anonymous is accessible to both admin and uh both admin and uh employees so this is an anonymous page okay all right so let's go ahead and uh start running it and it's assigning some roles let's put a break point here on the post and see what's wrong I'm sorry what's right okay so what we are going to do is assign cleanse I'm not sure if it's there in the layout it's probably not there okay now I'm sorry I'll have to stop it because I do not have the link to assign pages in uh yeah in the in the layout so uh products let's have it somewhere here assign claims and access claims is the controller okay perfect I'm not missing anything fine all right guys now uh if I try to assign claims it will ask me for a login privacy I'm able to open home I'm able to open so uh login if I'm using by any other username so like an employee I will be able to log in but I will not be able to uh get into assign claims perfect logged out login as admin go to assign claims now I have to assign okay I'm logged in as admin so I won't be able to access HR um tonight won't be able to access manager won't be able to access assigned claim oh sorry assigned Glimpse I'm able to access another one I'm able to okay let's see uh let's assign this to one user so we have uh three users with roles let's assign them with employee roles so these are the three users which have uh employee roles 67 A7 F7 okay so Usha kalas and Kishore okay so let's assign Usha and Clem's head Let's uh put Usha as a manager and okay this claims head this should match uh this should match your keyword what is my programs this this keyword okay this keyword it should match that keyword the claims head okay claims value is management and I'm saving it okay it's a build and it's going to yeah we sent all the variables in the parameter so user email claims name or the claims head and the claims value and then find my name is using this email to make it an identity user okay this is not just assigning a value it's making it an identity user okay so even though it got the email but it it's used as an identity user okay so add cleanse async will use this identity user value and then the head and the value continue claims created successfully okay now let's go here see we got one claims assigned it's an employee and has the management role the management claim now let's assign another guy manager is already assigned let's assign an HR Okay so Usha is already assigned now let's assign Kishore as an HR Clem's head is the keyword that's matching uh the one that's in your program files in the program.cs okay you can use it as a drop down uh we can we can get this policies in using a drop down I might be able to show it in a different program but not this one okay I'm already uh yeah worked on the codes so Okay so claims created successfully check here we have two claims now okay let's leave the other one okay one that's kalash let's leave it blank so we have two uh user claims who are employees all right now login as the one that is not assigned so kailash we haven't Clash is just an employee and has no claims okay logged in now go to assign claims uh it doesn't have access to assign claims he's just a normal user okay so he will have access to products but he's an employee so he is able to access the products okay let's see the products controller where is where is it where is it probably closed it products controller is accessible by employees so he is able to access products uh controller but assign claims is not I guess uh assigned claims was accessible by employees too then why is he not oh we did not uh no he is an employee index and it's uh should be assigned should be able to what's wrong I'm sorry let me check that sorry guys I made a mistake here employees this is not employee this is employees and uh the products controller has employees that's why okay so save it logged in as kalash and I'm trying to get into assign claims I'm able to assign uh get into it look for anonymous anonymous is accessible to kalash even though he is an employee but he doesn't have any claims and now if he tries to get into any more any other options from them he has an access tonight page okay so he cannot assign any uh he cannot access anything else all right let's log him out and let's login as a different user now let's go ahead with Kishore Kishore is an HR so Kishore logged in and he has access to privacy he has access to products he has access to assigned claims he has access to Anonymous in assigned claims if he tries to ask access manager who is denied if he tries to get into a sign claims he's denied if he tries to get into HR he is able to access that page log him out Kishore uh worked as an HR now um the last one I think is Usha uh F7 F7 Kishore and 67 yeah Usha all right so let's log in with Usha and uh we are able to access privacy with that ID we are able to access assign claims we are trying to get into HR we're getting access tonight we are trying to get an assign claims we are denied and we can get into anonymous we are able to get into it uh get into manager he's able to uh this place is able to access to management employees only okay so which is able to access management employees so that's all guys so you you saw like how it worked for uh the policies authorized policy which has management which has HR which has admin admin is a role okay and without them only employees and admins are able to access all other pages um so pretty much if you want to have a look at the codes uh access claims controller is the one that is created for Access claims I haven't used this context application DB context in this program maybe I'll use that in a different one so initialize the role manager and the user manager user manager is used in assigned claims we are using the email uh the Clem's head and the value so user I'm I'm using the email to get into a value of user because uh this converts it this where user it becomes like an identity user okay so we can use this value as an identity user in ad claims we cannot use an email directly in the ad claims that's why and then claims name is the head this claims value is the description and then it saves it as a glimpse value okay so yep that's all guys uh pretty much that's uh all for today if you want to have a look up at the role based authentication that's the previous video of this one you can have a look at it and keep watching stay tuned with us and give us your support thanks for watching thanks for your day have a good day bye
Info
Channel: Fired Developer
Views: 278
Rating: undefined out of 5
Keywords: claims authentication in dotnet core identity, claims authentication
Id: CWlA142ybTM
Channel Id: undefined
Length: 20min 49sec (1249 seconds)
Published: Wed May 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.