From the course: Advanced Web APIs with ASP.NET Core in .NET 6

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Adding token-based authentication

Adding token-based authentication - C# Tutorial

From the course: Advanced Web APIs with ASP.NET Core in .NET 6

Adding token-based authentication

- In order to add token based authentication to our API we need to do some extra steps and I've decided that I will implement everything and show you the result. That's probably a bit more efficient than you watching me type for an extended amount of time. Everything takes place in the existing web application; pages based web application to be precise. And the first thing I did was I went to the program CS file and added support for controllers because I would like to add a controller and that controller will both serve as an endpoint to generate a token. And also as an API endpoint, that will then be protected. And that call to 'build.services.addcontrollers' will be complemented by 'app.mapcontrollers'. Right? So now the application supports ABC and APIs as well. I then created a controllers folder and in that I set up a new API controller called Token Controller. And you see from a number of usings here at the top that there…

Contents