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

Associate user with quiz and question

From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core

Start my 1-month free trial

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…

Contents