Sobes.tech
Junior — Middle

Explain what a JSON Web Token is and what it is used for in modern web applications.

sobes.tech AI

Answer from AI

JSON Web Token (JWT) is a compact, URL-safe way to transmit information between parties as a JSON object. JWT consists of three parts: header, payload, and signature.

In modern web applications, JWT is often used for user authentication and authorization. After a successful login, the server generates a JWT, which the client stores (for example, in localStorage) and sends with each request. The server verifies the token's signature to confirm its authenticity and extracts user data without needing to store a session on the server.

Example of a JWT structure:

header.payload.signature

Where:

  • header — contains the token type and signing algorithm.
  • payload — contains claims, such as user ID and expiration time.
  • signature — cryptographic signature to verify integrity.

This allows for scalable and secure stateless authentication systems.