How to download, run and test an example ASP.NET Core 3.1 JWT Authentication API with Postman.

In this tutorial we’ll go through a simple example of how to implement JWT (JSON Web Token) authentication in an ASP.NET Core 3.1 API with C#.The example API has just two endpoints/routes to demonstrate authenticating with JWT and accessing a restricted route with JWT:

  • /users/authenticate - public route that accepts HTTP POST requests containing the username and password in the body. If the username and password are correct then a JWT authentication token and the user details are returned.
  • /users - secure route that accepts HTTP GET requests and returns a list of all the users in the application if the HTTP Authorization header contains a valid JWT token. If there is no auth token or the token is invalid then a 401 Unauthorized response is returned.

The tutorial project is available on GitHub at https://github.com/cornflourblue/aspnet-core-3-jwt-authentication-api.

#asp-net #c-sharp #jwt #security #json

How to implement JWT Authentication in an ASP.NET Core 3.1 API with C#
35.15 GEEK