9 Authentication and authorization
This chapter covers
- Authentication and Authorization general concepts
- ASP.NET Core Identity overview
- Implementing authentication via user accounts and JSON Web Tokens (JWT)
- Implementing authorization using AuthorizeAttribute and IAuthorizationFilter
- Third-party Auth providers
The ASP.NET Core Web API that we have built throughout the previous chapters has taken a rather solid shape. Before being able to publish it, however, we must address some major security permissions issues that we have intentionally left open: if we take a closer look at our BoardGamesController
, DomainsController
, and MechanicsController
, we can easily see how they all have some Post
and Delete
methods that could be used by anyone to permanently alter our valuable data. We definitely don’t want that, do we?
For that very reason, before ever thinking of deploying our Web API over the internet and making it publicly accessible, we need to find a way to restrict the usage of those methods to a limited set of authorized users.
In this chapter we’ll learn how to do that using ASP.NET Core Identity, a built-in API that can be used to manage users, roles, claims, tokens, policies, auth-related behaviors, and more.
9.1 Basic concepts
Before delving into the code, it is appropriate to provide a general overview of the concepts of authentication and authorization. Although often used in the same context, the two terms have a distinct and precise meaning.