Authentication implementation using JWT
The JWT or JSON Web Token is a type of token for carrying identity data between machines. It is supported by different programming languages, an industry standard, and can be easily passed around. A JWT is self-contained, and it holds the needed identity information within itself, as shown in the following figure:
The preceding Figure 9.4 shows the three parts of the JWT: the header, payload, and signature. The header has two properties. One is alg
, which is short for algorithm, which determines the algorithm used for encoding this token. typ
is JWT
. We don't have to worry about this header because this is just a standard.
What matters to us is the second part, which is the payload. So here, we have a JSON object with three properties: sub
, usually a user ID, name
, and iat
, which is when the token was generated. What you need to know here is that the payload includes public...