From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Associate user with quiz and question
From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core
Associate user with quiz and question
- [Instructor] Now that we're able to make our post New Quiz end point an authorized end point, we can also get the user Id and user account through the token that's passed to the back end. At that point, we can easily say associate this new quiz with the user that tried to request posting it. To get that going, we'll need a little bit of set up. So let's go to our back end project and stop the server. The first thing we'll need to do is add the user Id to the JSON Web Token. We can do that with something called a claim. So let's go above our signingKey on line 45 and add a new line. We'll call it claims, and we'll set it to new Claim, and we'll initialize it. But first, let's add the name space, Security.Claims. Then we'll add a new claim and we'll pass in JwtRegisteredClaimNames.sub for subject, which in this case will be the user Id. Next, let's go down to where we create our jwt on line 54 and add our claim. Now, our user Id is embedded in the token itself, and when a new user…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Set up Identity Framework13m 31s
-
(Locked)
Register from Angular4m 26s
-
(Locked)
Reactive forms with FormBuilder5m 49s
-
(Locked)
Save token in the browser3m 39s
-
(Locked)
Pass token with Angular requests5m 6s
-
(Locked)
Auth token middleware in ASP.NET7m 55s
-
(Locked)
Associate user with quiz and question5m 35s
-
(Locked)
Logging in6m 38s
-
(Locked)
Logging out3m 23s
-
(Locked)
-
-