.NET 6 Web API Authentication | Minimal API & Swagger (CRUD)

In this tutorial we’ll create a .NET 6 Web API (Minimal API) that will enforce JWT Authentication and Authorization. Furthermore, we’ll add Swagger support and configure Bearer Authentication for it, so that all of our endpoints can be testable from Swagger UI using a bearer token.

By the end of this tutorial, you will know:
– How to create a Minimal API project
– Create and use Data Transfer Objects
– Create Services that expose data
– Understand the basics Minimal API in .NET 6
– Setup a CRUD .NET 6 Web API (Minimal API) that will expose services methods
– Configure the API Endpoints for Authentication and Authorization with JWT Bearer
– Setup Swagger support and configure bearer authentication with Swagger
– Understand the basics of Swagger Documentation in .NET 6

For this tutorial there are two pre-requisites .NET 6 and Visual Studio 2022. Here is a video showing where to download these from: https://youtu.be/kM1fPt1BcLc

Source code: https://github.com/iulianoana/MinimalAPIAuth-Swagger

👉Join our monthly email club: https://signup.codewithjulian.com
🎉Check Out Further Resources: https://codewithjulian.com
👍If you enjoyed this tutorial, please like this video consider subscribing for more content like this!
😎Subscribe for endless .NET Tutorials: https://www.youtube.com/c/CodewithJulian

0:00 – Intro
0:21 – Create Minimal API Project
1:02 – Add Data Transfer Objects
2:47 – Add Data Repositories
4:59 – Creating Services
11:09 – Install JWT Dependencies
12:17 – Configure Minimal API Endpoints
20:41 – Add Swagger Support
23:30 – Add JWT Authentication
29:03 – Generate JWT on Login
35:05 – Configure Endpoints for Authentication
38:27 – Configure Bearer Authentication in Swagger
43:43 – Swagger Documentation

Useful Links:
Enterprise CRUD API Controller: https://youtu.be/aU-skkVpjII
Basics of JWT: https://youtu.be/Pn_rTbvWW4w
– Microsoft.AspNetCore.Authentication.JwtBearer –version 6.0.0
– Microsoft.IdentityModel.Tokens –version 6.14.1
– System.IdentityModel.Tokens.Jwt –version 6.14.1
– Swashbuckle.AspNetCore –version 6.2.3

– Sound effects obtained from https://www.zapsplat.com
– Icons designed by http://www.freepik.com and https://www.flaticon.com/
– Images from the artists on https://unsplash.com/