In many other cases, however, we can use a more performant approach that does not compromise on security either: JSON Web Tokens (JWTs).
The approach differs only slightly from the preceding one:
- The user logs in with the authentication manager.
- The authentication manager returns a security token that contains the user information, encrypted.
- Another microservice can now self-verify the token and get the relevant user information out of the token.
A JWT consists of three parts:
- Header: This describes the algorithm used for the signature as well as the nature of the token. In many cases, it looks similar to this: {"alg": "HS256", "typ": "JWT"}.
- Payload: Here we have the data we care about most, user information and timing ...