This tutorial presents .NET 5 Web API security with JSON Web Token (JWT).

  1. Create a .NET 5 Web API project with default settings.
  2. Add necessary NuGet packages.
  3. Create JWT consumer service extension method with JWT payload parameters. Then, register it in the Startup class along with the app.UseAuthentication() middleware.
  4. 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.
  5. Create API controller method and decorate it with [Authorize] attribute.
  6. Create JWT by using the saved payload parameters and give it to the client.
  7. 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

.NET 5 Web API Security with JSON Web Token (JWT) With Example for Beginners #15
1.35 GEEK