JWT, or JSON Web Token, is a compact and self-contained method for securely transmitting information between parties as a JSON object. It is commonly used for authentication and authorization in web applications.
When a user logs in, the server creates a JWT that contains the user's identity and possibly other data, signs it with a secret key, and sends it to the client. The client then includes this token in subsequent requests, typically in the Authorization header, to prove its identity without needing to send credentials again.
A JWT consists of three parts: a header (which specifies the token type and signing algorithm), a payload (which contains the claims, such as user ID or expiration time), and a signature (which verifies that the token hasn't been altered). These parts are Base64Url-encoded and separated by dots.
JWTs are stateless, meaning the server doesn't need to store session information; all necessary data is within the token. This makes them scalable for distributed systems and APIs.