This tutorial presents .NET 5 Web API security with JSON Web Token (JWT).
- Create a .NET 5 Web API project with default settings.
- Add necessary NuGet packages.
- Create JWT consumer service extension method with JWT payload parameters. Then, register it in the Startup class along with the app.UseAuthentication() middleware.
- Create a user secret file and save the JWT payload parameters in it. Note that these payload parameters must the same those in the JWT consumer service extension method.
- Create API controller method and decorate it with [Authorize] attribute.
- Create JWT by using the saved payload parameters and give it to the client.
- Then, client will access the JWT protected controller method by using the provided JWT.
Link to the source code:
https://github.com/Muhtar-Qong/AspDotNetCoreApi
#json #jwt #dotnet #dotnet5