Testing with authentication and authorization
A common scenario in web APIs is that some API endpoints require authentication and authorization. We introduced how to implement authentication and authorization in Chapter 8. In this section, we will discuss how to test the API endpoints that require authentication and authorization.
Preparing the sample application
To demonstrate testing with authentication and authorization, we will use the sample application we created in Chapter 8. You can find the source code in the chapter10\AuthTestsDemo\start\
folder of the sample repo. This sample application uses claims-based authentication and authorization. You can recap the implementation details in Chapter 8.
In WeatherForecastController
, there are several methods that require authentication and authorization. (Forgive the naming – we just use the default template of ASP.NET Core web APIs.)
Create a new integration test project as described in the Setting up the integration...