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.

Generating a token

Generating a token

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

Start my 1-month free trial

Generating a token

- [Narrator] Before we start implementing the Token generation, it is important to know what a Token is. And a Token is a piece of data which is created by a server, in our case, the Web API, and this piece of data contains enough data to identify a user. So, let us create a method which we are going to use to generate Tokens when we want to sign in or create a user. So for that, let us go to our Web API project. In the authentication controller, after the register method, let us write in here, private object, and then CreateToken. This method is going to take as a parameter via user. So user and then user. Now we don't want to just return a general object, we want to return a JWT Package and this package is going to contain our Token string, and the Username. So for that let us write in here, JwtPackage. Now, since this does not exist, let us create it in our line 37, for that write, public class JwtPackage. And this class will have two properties. The first property is going to be…

Contents