JWT Decoder

JWT Decoder

Decode and inspect JSON Web Tokens (JWT) payload instantly

Securing the Web: What is a JWT?

A JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA. In modern web development, JWTs are the primary mechanism for authentication and authorization in Single Page Applications (SPAs) and microservices architecture.

The Anatomy of a JWT

A JWT consists of three parts, separated by dots (.), which are encoded in Base64Url:

  • Header: Typically consists of two parts: the type of the token, which is JWT, and the signing algorithm being used, such as HMAC SHA256 or RSA.
  • Payload: Contains the "claims." Claims are statements about an entity (typically, the user) and additional data. There are three types of claims: registered, public, and private claims.
  • Signature: To create the signature part, you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.

Understanding JWT Claims

Claims are the meat of the JWT. Standard registered claims include:

  • iss (Issuer): Identifies the principal that issued the JWT.
  • sub (Subject): Identifies the principal that is the subject of the JWT (e.g., user ID).
  • aud (Audience): Identifies the recipients that the JWT is intended for.
  • exp (Expiration Time): Identifies the expiration time on or after which the JWT must not be accepted for processing.
  • iat (Issued At): Identifies the time at which the JWT was issued.

Why You Need a JWT Decoder

When developing an application, you often need to check if the claims in your token are correct. Is the expiration time set properly? Does the user ID in the 'sub' claim match your database? Since JWTs are Base64 encoded, they look like gibberish at first glance. A JWT Decoder allows you to instantly see the raw JSON data inside without having to write any code. This is particularly useful for frontend developers who need to check why their application thinks a session has expired or for backend developers verifying the tokens generated by their authentication service.

Security Note

It is crucial to remember that decoding a JWT is not the same as verifying it. Decoding simply shows you the information inside. Anyone who gets hold of your JWT can decode it. This is why you should never put sensitive information like passwords or private keys inside a JWT payload. Verification, on the other hand, requires a secret or a public key to ensure that the token hasn't been tampered with. This tool provides decoding for inspection purposes and does not perform cryptographic verification.

Frequently Asked Questions

What does JWT stand for?

JWT stands for JSON Web Token.

Can I see the password in a JWT?

No. A JWT should never contain passwords. It contains 'claims' which are usually user identifiers, permissions, or session data. If a developer put a password in a JWT, it would be visible to anyone who has the token.

How do I decode a JWT manually?

You can take the first two parts of the JWT (separated by dots), and use a Base64Url decoder. In JavaScript, you can use `atob(part.replace(/-/g, '+').replace(/_/g, '/'))` after parsing the JSON.

What is the difference between a JWT and a Session Cookie?

Session cookies are stored on the server, and the browser sends a session ID to the server to look up the data. JWTs are 'stateless'—all the data is stored within the token itself, which is sent by the client. This makes JWTs ideal for scaled, distributed systems.

Is Base64 the same as encryption?

Absolutely not. Base64 is an encoding format, not encryption. It is used to make binary data safe for transport as text. It provides zero security. Anyone can decode Base64 back to its original form.

Why is there a signature in a JWT?

The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way.

What happens when a JWT expires?

When the current time is greater than the value in the 'exp' claim, the token is considered invalid. The server will reject any requests made with an expired token, forcing the user to re-authenticate or refresh their token.

What is a Refresh Token?

Since JWTs are usually short-lived for security, a Refresh Token is a long-lived token used to obtain new JWTs without making the user log in again.

Can I use JWT for logout?

Logging out with JWTs is tricky because they are stateless. To truly 'logout' before expiration, you usually need to maintain a 'blacklist' of revoked tokens on your server, or wait for the token to expire naturally.

How long should a JWT be valid?

Best practices suggest short-lived access tokens (15 minutes to 1 hour) combined with longer-lived refresh tokens for the best balance between security and user experience.

Is my token sent to your server?

No. This JWT Decoder runs entirely in your browser. Your tokens never leave your computer, ensuring total privacy.

What algorithm is most common for JWT?

HS256 (HMAC with SHA-256) is very common for simple applications, while RS256 (RSA Signature with SHA-256) is standard for larger systems using public/private key pairs.