From the course: Security in ASP.NET Core

Unlock this course with a free trial

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

Securing APIs

Securing APIs

- [Instructor] I have expanded program.cs a little bit. I have added a couple of NuGet packages for Swagger support. So you are guessing correctly, we are working with APIs now. I also added some boilerplate code that is needed for because of restriction in ASP.NET Core. It has to do with APIs that need authorization and if we are not authorized, then they might redirect to the login page, which doesn't make sense in an API, right? But now I'd like to add an API. So how about something really simple? We are using a minimal API and I would say the endpoint could be called /api/hello because I'd like to return, well, the name of the current user, I get that name through the HTTP context. So I'm using dependency injection to get it here. And then in the implementation, well essentially I'm just returning a string, the string is hello and then using variable interpolation HTTP context with a lowercase age, which (indistinct) is kind of preventing me doing. Okay, now it's working and then…

Contents