Implementing JSON web token authentication

In order to handle JWT-based token authentication, we need to implement the required middleware for doing these tasks:

  • Generating the JWT tokens upon username/password POST requests coming from our client.
  • Validating any JWT token coming with requests by looking at their headers and cookies

Although ASP.NET Core natively supports JWT tokens, the only available middleware is the one validating the request headers (JwtBearerMiddleware). This leaves us with two choices: manually implement what's missing or rely on a third-party library that does just that. We'll try the hand-made route throughout the rest of this chapter, leaving the other alternative to the following chapter.

The first thing to do is define ...

Get ASP.NET Core: Cloud-ready, Enterprise Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.