Introduction

A JSON Web Token, commonly written as JWT, is a compact, signed token that carries information about a user or a session. A token is a signed piece of data that represents a fact. A claim is a single statement within the token, such as the identity of the user. This guide explains what a JWT is, why it exists, how it is created and validated, and how it should be handled.

What is it?

A JWT is a string that is composed of three parts, separated by dots. The header states the type of the token and the algorithm that is used to sign it. The payload contains the claims. The signature is a value that is used to verify that the token has not been altered. Each part is encoded so that it can be transmitted safely as text. The token is signed rather than encrypted, which means that its contents can be read, while the signature prevents it from being changed without detection.

Why does it exist?

Traditional sessions require the server to store a record for every signed-in user and to look up that record on each request. This becomes difficult when many servers must share the same session information. A JWT was designed so that authentication can be stateless, meaning that the server does not need to store session records. Because the token is self-contained and signed, any server that holds the signing key can verify it without a central store.

How it works

An issuer, such as Amazon Cognito, creates a token, adds the claims, and signs it with a key. The client stores the token and sends it with each request, usually in the Authorization header with the word Bearer in front of it. The receiver verifies the signature using the key, which confirms that the token is genuine and unaltered. The receiver then checks standard claims, such as the expiration time, the issuer, and the intended audience, before access is granted. The expiration claim states the time after which the token is no longer valid.

Structure diagram

A JWT is three parts joined by dots: header . payload . signature header -> token type and signing algorithm payload -> the claims (user id, expiry, issuer, audience) signature -> verifies the header and payload were not changed The receiver checks the signature, then the claims, before access is granted.

Advantages

Disadvantages

Common use cases

Best practices

Common mistakes

Further reading in this library

Frequently Asked Questions

Is a JWT encrypted?
No, not by default. A standard JSON Web Token is signed but not encrypted, so its contents can be read by anyone who holds it. Sensitive information should not be placed in a token.
What are the three parts of a JWT?
A header, a payload, and a signature, separated by dots. The header states the type and algorithm, the payload contains the claims, and the signature verifies that the token has not been changed.
Can a JWT be revoked before it expires?
Not easily. Because it is self-contained and validated without a central store, it remains valid until it expires. Early revocation requires an additional mechanism, such as a short expiry combined with a list of tokens that are no longer accepted.
What is a claim?
A claim is a single statement inside the payload, such as the identifier of the user, the expiry time, or the issuer. Claims are the information that the receiver reads and checks.
Where should a JWT be stored in a browser?
It should be stored so that it is not exposed to injected scripts. A secure, http-only cookie is generally safer than storage that scripts can read, and the token should always be sent over an encrypted connection.
AWS Cognito book cover
Go deeper ยท Book as a Service™
AWS Cognito

This article is the summary. The book is the full, continuously updated reference: tokens, validation, Lambda triggers, securing APIs, and real-world integration.

View the book