From the course: Building and Securing Restful APIs in .NET

Unlock the full course today

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

Securing APIs with API key

Securing APIs with API key

- [Instructor] For our first example of authentication, I'm going to close all these down and go back to our weather forecast controller, and I want to start by being able to declaratively say that I want you to have to authenticate to use this. So I'm going to use the authorized attribute and indicate particular authentication scheme that you need to use called the API key. Now that's not built in, that's something that I have decided and we're going to use and create. You'll see we've got some new namespace using statements up at the top there for authorization. So this attribute simply says, to access this controller, you can have to authenticate with this scheme. That in and of itself doesn't do anything for us, it will just cause us not to be able to access it yet. So we need to go and fix that up, but what it will look like on the client, if we come out here and go back up to the top, we know we've got our weather forecast and we want the client to be able to pass an…

Contents