From the course: Building Angular and ASP.NET Web API Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Requesting a token from Angular

Requesting a token from Angular

From the course: Building Angular and ASP.NET Web API Apps

Start my 1-month free trial

Requesting a token from Angular

- [Narrator] Now that we have implemented the token generation, it is time to learn how to use the token to authenticate the users. And for that, we are going to go through three main steps. So we will first get the token, then we will store it in our local storage, and then later we are going check if the token exist or not. So let us start with the web API project. Inside the controls folder, go to the authentication controller. And then scroll down to the register method. And we are going to use this method to register a user. So let us create a try and catch block and in case something goes wrong, we want to return to the users a bad request message so for that we write return bad request and then we add a name for the exception ex, and here we write ex dot message. Inside our try block, let us use the AppDbContext for that using var context is equal to new AppDbContext and then import the necessary name space. Now that we have the context let us check if the user already exists…

Contents