Using authentication in a Minimal API with Swagger

Download the code example to learn how to add API key security to Minimal API endpoints

You can learn about the simplest way to add authentication to Minimal API endpoints, or watch the video.

Download the code example

You'll need to fill out the code example form. We will send you an email where you can download the code example.

Software

This is the software that will need to be installed onto your machine.

The application

Open up RoundTheCode.MinApiSecurity.slnx, and run the application. The Swagger documentation will load at https://localhost:7083/swagger.

Try running the single endpoint and it will return 401 Unauthorized.

Then, click on the Authorize button in Swagger and enter the API key. The API key can be found in appsettings.Development.json.

Run the endpoint now and it should return 200 OK.