What Is a JWT? JSON Web Tokens Explained, Safely

A JWT (JSON Web Token) is a signed string with three parts: header, payload and signature. Anyone can decode the first two. The signature proves nobody changed them.

Gary · Published · Updated · 16 min read

Isometric illustration of three glowing emerald blocks in a row on a dark slate base, joined by small light dots and linked by a dashed line to a verifier block.
On this page
  1. What is a JWT (JSON web token)?
  2. What's inside a JWT token? Header, payload and signature
  3. Why does a JWT start with eyJ?
  4. Can anyone decode a JWT?
  5. How does JWT authentication work?
  6. Why does the header say "Bearer" first?
  7. How is a JWT signed and verified?
  8. The tamper test
  9. How do JWTs expire, and can you revoke one?
  10. Refresh-token rotation and revoking on logout
  11. JWT vs session cookie vs API key
  12. Where JWTs show up in Supabase and Firebase apps
  13. Where to store a JWT: httpOnly cookie vs localStorage
  14. JWT safety mistakes that leak data
  15. Is JWT deprecated?
  16. FAQ

What is a JWT? A JWT, or JSON Web Token, is a short string an app uses to prove who you are. It has three parts joined by dots: a header, a payload with facts about you (called claims), and a signature. Anyone holding the token can read the header and payload. The signature is what lets a server tell whether someone changed them.

By Gary, Greenlight My App. Checked Nov 3, 2026. How we checked this: we read RFC 7519, RFC 8725, RFC 6750 and RFC 7009 plus the Supabase, Firebase, OWASP, MDN and Auth0 docs on Nov 3, 2026, and quote them below. Our team also made a demo JWT with a 9-line Python 3.13.5 script (standard library only) and a made-up secret on Nov 3, 2026, then decoded, verified, tampered with and expired it. The terminal screenshots are from that run, with the demo token text masked. Drafted with AI tools and reviewed by a person before publishing.

What is a JWT (JSON web token)?

The standard that defines JWTs is RFC 7519 (external). Its first line says: "JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties."

A claim is just a fact, written as a JSON field. "This user's ID is 123." "This token expires at 3 PM." "This user has the role authenticated."

And if you've wondered how to say it, the RFC answers that too: "The suggested pronunciation of JWT is the same as the English word "jot"."

Supabase's JWT guide (external) gives a friendlier definition: "A JSON Web Token is a type of data structure, represented as a string, that usually contains identity and authorization information about a user. It encodes information about its lifetime and is signed with a cryptographic key to make it tamper-resistant."

So what is JWT used for? Mostly sign-in. After you log in, the auth server gives your app a JWT. Your app sends it with each request, and the API reads it to learn who you are and what you can do.

What's inside a JWT token? Header, payload and signature

RFC 7519 describes the shape: "A JWT is represented as a sequence of URL-safe parts separated by period ('.') characters. Each part contains a base64url-encoded value."

Diagram of the three parts of a JWT: the header decodes to the algorithm and type, the payload decodes to claims like sub, role and exp and is readable by anyone, and the signature proves nobody changed the claims.

PartWhat it holdsExample (decoded)Secret?
HeaderThe token type and signing algorithm{"alg":"HS256","typ":"JWT"}No, anyone can read it
PayloadClaims: user ID, role, issue and expiry times{"sub":"demo-user","role":"anon","exp":1793710631}No, anyone can read it
SignatureA signature over header + payloadXXXX (random-looking bytes)Not secret, but only the key holder can make a valid one

Common claims you'll see in the payload:

  • sub: the subject, usually the user ID.
  • exp: the expiry time, in seconds since 1970.
  • iat: when the token was issued.
  • iss: who issued it.
  • aud: who it's meant for.
  • role: in Supabase, "The Postgres role to use when applying Row Level Security policies."

Why does a JWT start with eyJ?

Because the header is JSON, and JSON objects start with {". When you base64url-encode {", the first three characters come out as eyJ. The payload is JSON too, so the second part usually starts with eyJ as well.

That's handy. If you see a long string like eyJhbGciOi… followed by two dots, it's almost certainly a JWT. It's also why secret scanners look for that pattern in public code.

Here's the demo script our team used (we only changed the comment). It builds the header and payload, then signs them with HMAC-SHA256. The secret below is a placeholder.

Python

import base64, hmac, hashlib, json, sys, time
SECRET = b"XXXX"  # placeholder, never hard-code a real secret
def b64(b): return base64.urlsafe_b64encode(b).rstrip(b"=").decode()
def make(exp_in):
    h = b64(json.dumps({"alg":"HS256","typ":"JWT"},separators=(",",":")).encode())
    p = b64(json.dumps({"sub":"demo-user","role":"anon","iat":int(time.time()),"exp":int(time.time())+exp_in},separators=(",",":")).encode())
    s = b64(hmac.new(SECRET, f"{h}.{p}".encode(), hashlib.sha256).digest())
    return f"{h}.{p}.{s}"
print(make(int(sys.argv[1]) if len(sys.argv)>1 else 3600))

Terminal screenshot from our Nov 3, 2026 run: the 9-line Python script that builds an HS256 JWT with a placeholder secret, and the demo token it printed (token text masked by us before publishing).

Can anyone decode a JWT?

Yes. This surprises a lot of people. The header and payload are only base64url-encoded, so you can read them without any key, any website or any special tool.

Our team decoded the demo token with plain command-line tools:

Bash

echo "$T" | cut -d. -f1 | tr '_-' '/+' | base64 -d
echo "$T" | cut -d. -f2 | tr '_-' '/+' | base64 -d

Terminal screenshot from our run: the demo token's header decodes to alg HS256 and typ JWT, and its payload decodes to sub demo-user, role anon, iat and exp, using only base64 and no secret.

RFC 7519 is blunt about what that means for privacy: "A JWT may contain privacy-sensitive information." Its advice: "Omitting privacy-sensitive information from a JWT is the simplest way of minimizing privacy issues."

So don't put passwords, API keys, card numbers or private notes in a JWT payload. Treat everything in it as public.

A quick word on online JWT decoders: they work, but pasting a live token into a website hands that token to the site. For a real token, decode it locally like we did above, or use a test token.

There is an encrypted kind of JWT (called JWE), but most login tokens you'll meet are only signed. Signed means anyone can read it. Only the signature is protected.

How does JWT authentication work?

Here's the usual flow in a web app:

  1. You sign in with a password, a passkey or a social login.
  2. The auth server checks you, then signs a JWT that says who you are and when it expires.
  3. Your app keeps the token and sends it with each API request, usually in an Authorization: Bearer header.
  4. The API checks the signature and the expiry. If both are good, it trusts the claims.

Diagram of how JWT authentication works: the app sends a login to the auth server, which signs a JWT with a short expiry; the app sends the JWT with each request as an Authorization Bearer header; the API verifies the signature, exp, iss and aud before reading the claims, and rejects the request if any check fails.

Supabase works this way. Its docs say "Your Supabase project accepts a JWT in the Authorization: Bearer <jwt> header. If you're using the Supabase client library, it does this for you."

Firebase does too. Its docs say that after sign-in you can "send that JSON Web Token (JWT) to your backend and validate it using the Firebase Admin SDK."

The big win is speed. The API doesn't need to look up a session in a database on every request. It just checks the signature.

Why does the header say "Bearer" first?

The word is the auth scheme, and the token comes after it. RFC 6750 (external), the OAuth 2.0 bearer token spec, defines the format as "Bearer" 1*SP b64token: the word Bearer, a space, then the token. It says clients "SHOULD make authenticated requests with a bearer token using the "Authorization" request header field with the "Bearer" HTTP authorization scheme."

The name tells you how the token works. RFC 6750 says "any party in possession of the token (a "bearer") can use the token in any way that any other party in possession of it can." There's no extra proof step, so whoever holds the token can use it. That's why the spec says tokens "SHOULD NOT be passed in page URLs" and should always travel over HTTPS.

How is a JWT signed and verified?

The signature is made from the header and payload plus a key. If anyone changes a single character of the payload, the signature no longer matches.

There are two main ways to sign:

  • HS256 uses one shared secret. The same secret signs and verifies. Anyone who has it can make valid tokens.
  • RS256 (and ES256) use a key pair. A private key signs; a public key verifies. The public key can be shared safely.

Firebase ID tokens use the key-pair kind. Firebase's docs list the header alg as "RS256". Supabase now supports both and leans hard toward key pairs. Its docs warn: "There is almost no benefit from using a JWT signed with a shared secret."

The tamper test

We changed the demo payload's role from anon to admin and kept the old signature. Our verifier (below, comment shortened) rejected it:

Python

import base64, hmac, hashlib, json, sys, time
SECRET = b"XXXX"  # placeholder
def ub64(s): return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
h, p, s = sys.argv[1].split(".")
good = base64.urlsafe_b64encode(hmac.new(SECRET, f"{h}.{p}".encode(), hashlib.sha256).digest()).rstrip(b"=").decode()
if not hmac.compare_digest(good, s): sys.exit("FAIL: invalid signature")
c = json.loads(ub64(p))
if time.time() >= c["exp"]: sys.exit(f"FAIL: token expired (exp={c['exp']}, now={int(time.time())})")
print("OK: signature valid, not expired:", c)

Terminal screenshot from our run: the verifier script accepts the untouched demo token and prints OK: signature valid, not expired, with the decoded claims.

Terminal screenshot from our run: the original and tampered demo tokens (header and payload masked by us) share the same signature; after the role was changed from anon to admin, the verifier prints FAIL: invalid signature.

That's the whole point of the signature. But it only protects you if your server actually checks it. RFC 7519 says "The contents of a JWT cannot be relied upon in a trust decision unless its contents have been cryptographically secured."

In real apps, use a well-known JWT library or your auth provider's SDK rather than a hand-rolled script like ours. Supabase says to "avoid implementing the algorithms yourself."

How do JWTs expire, and can you revoke one?

Every serious JWT carries an exp claim. RFC 7519 says it "identifies the expiration time on or after which the JWT MUST NOT be accepted for processing."

We made a demo token that lived for 2 seconds, waited 4, and checked it:

Terminal screenshot from our run: a demo token made with a 2-second lifetime is checked after sleeping 4 seconds, and the verifier prints FAIL: token expired with the exp and current times (token text masked by us).

Revoking is harder. A server that only checks the signature will keep accepting a stolen token until it expires. That's why tokens are kept short.

Supabase's sessions guide (external) says: "Access tokens are designed to be short lived, usually between 5 minutes and 1 hour while refresh tokens never expire but can only be used once." It also says "Most applications should use the default expiration time of 1 hour."

Firebase adds a warning about its own verify method: "This does not check whether or not the token has been revoked." If you need instant sign-out everywhere, you need an extra check on the server.

Refresh-token rotation and revoking on logout

Short access tokens need a way to renew without a new login. That's the refresh token. Auth0's refresh token rotation guide (external) explains rotation: "every time an application exchanges a refresh token to get a new access token, a new refresh token is also returned." The old one stops working, so a stolen refresh token is only good until the real app uses it again.

Auth0 also describes reuse detection. If an already-used refresh token comes back, it "immediately invalidates the refresh token family," and the user has to sign in again.

Logout should end the session on the server too, not just delete the token in the browser. OWASP's Session Management Cheat Sheet (external) says "the web application must invalidate the session at least on server side." For OAuth tokens, RFC 7009 (external) defines a revocation endpoint that "allows a client to invalidate its tokens if the end-user logs out." Revoke the refresh token at logout. The access token still works until exp, which is one more reason to keep it short.

These three get mixed up all the time. Here's how they differ:

JWTSession cookieAPI key
What it identifiesA user (or service) and their claimsA user's session on the serverAn app or project
Where the data livesInside the tokenOn the server; the cookie holds an IDOn the provider's side
Can you read it?Yes, payload decodesUsually just a random IDUsually a random string
ExpiresWhen exp passesWhen the session endsUsually not until rotated
Easy to revoke?Not by defaultYes, delete the sessionYes, rotate it
Typical homeAuthorization header or a cookieBrowser cookie (ideally httpOnly)Server env vars; publishable keys in the frontend

Note that a JWT can live inside a cookie. "JWT vs cookie" is really about the format and where it's stored.

For the API key side, see what an API key is. For the passwordless login that often comes before a JWT is issued, see what a passkey is.

Where JWTs show up in Supabase and Firebase apps

Supabase user sessions. When someone signs in, Supabase Auth issues an access token JWT. Its docs say "Supabase Auth continuously issues a new JWT for each user session, for as long as the user remains signed in."

Supabase legacy keys. The older anon and service_role API keys are JWTs. Supabase's API keys guide (external) lists both as "JWT (long-lived)." It also says: "If a tool, tutorial, or AI assistant tells you to copy a long key that begins with eyJ, it was written for the legacy keys."

The newer keys are different: "Publishable and secret keys are short strings, not JWTs." Supabase adds: "Supabase is deprecating the anon and service_role keys by the end of 2026." Our guide to the Supabase publishable key covers the switch.

The anon key is meant to be public. Whether it's safe depends on your Row Level Security; see is my Supabase anon key safe?. The service_role key is the opposite. Supabase says secret keys "provide full access to your project's data, bypassing Row Level Security."

Firebase ID tokens. Firebase signs in users and gives the client an ID token, which is a JWT. Your server should verify it before trusting the uid inside.

Anything in localStorage can be read by any script on the page. OWASP's HTML5 Security Cheat Sheet (external) says: "Do not store session identifiers in local storage as the data is always accessible by JavaScript." If an attacker gets a script onto your page (cross-site scripting), a token in localStorage can be copied out.

An httpOnly cookie is different. MDN's Set-Cookie page (external) says HttpOnly "forbids JavaScript from accessing the cookie," which "mitigates attacks against cross-site scripting (XSS)." Add Secure so it's only sent over HTTPS, and SameSite for "some protection against certain cross-site attacks, including cross-site request forgery (CSRF)."

Cookies bring their own job. RFC 6750 says implementations that store bearer tokens in cookies "MUST take precautions against cross-site request forgery." So the trade is simple: localStorage is exposed to XSS, and cookies need CSRF protection.

JWT safety mistakes that leak data

Most JWT problems aren't about the format. They're about keys and checks. Here are the common ones:

1. Shipping the signing secret or a powerful key to the browser. Supabase warns that "It can be very easy to accidentally leak the shared secret in publicly available source code such as in your website or frontend, mobile app package or other executable." A leaked secret lets someone mint their own tokens. Supabase says it "can be used to impersonate your users, give them access to privileged actions or data." If a service_role key is already out, follow our service_role key exposed guide.

2. Putting private data in the payload. Anyone with the token can read it, as our decode test showed.

3. Not checking the signature, or trusting alg. RFC 8725, the JWT best-practices RFC, lists real attacks. One: "The algorithm can be changed to "none" by an attacker, and some libraries would trust this value and "validate" the JWT without checking any signature." Configure your library with the exact algorithm you expect.

4. Weak shared secrets. RFC 8725 warns that a human-memorable HS256 secret is weak: "Such keys are vulnerable to offline brute-force or dictionary attacks once an attacker gets hold of such a token."

5. Tokens that never expire. Long-lived tokens give a thief a long window. Keep exp short and refresh.

6. Storing tokens where any script can read them. OWASP's HTML5 Security Cheat Sheet (external) says: "Do not store session identifiers in local storage as the data is always accessible by JavaScript." An httpOnly cookie keeps a token away from page scripts.

7. Trusting a role the client sends. Never let the browser tell the server who is an admin. A role field in a request body, a header or a local token you didn't verify can be edited by anyone. OWASP's Authorization Cheat Sheet (external) says: "Developers must never rely on client-side access control checks." It adds that checks "must be performed server-side" and that "Permission should be validated correctly on every request." Read the role from a token your server has verified, or look it up in your database, and check it on every request.

A good way to keep secrets out of your frontend is to check your env var names. Supabase notes leaks are "especially true if you accidentally add the secret in environment variables prefixed with NEXT_PUBLIC_, VITE_, PUBLIC_ or other conventions by web frameworks."

Bash

SUPABASE_SECRET_KEY=sb_secret_XXXX
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_XXXX

The first line stays server-only. The second is fine in the browser.

Is JWT deprecated?

No. RFC 7519 is still the standard, and RFC 8725 (from February 2020) adds best practices on top of it. Supabase, Firebase and many other auth services use JWTs today.

What is being deprecated is specific keys. Supabase is retiring its JWT-based anon and service_role API keys in favor of publishable and secret keys. User session tokens in Supabase are still JWTs.

FAQ

Can a JWT be decoded? Yes. The header and payload are base64url-encoded, not encrypted, so anyone with the token can read them. Only the signature needs the key to create.

Is JWT deprecated? No. RFC 7519 is the current standard and is widely used. Supabase is retiring its JWT-based anon and service_role API keys, not JWTs in general.

Why does a JWT start with eyJ? The header is JSON, which starts with {". Base64url-encoding {" gives eyJ, so most JWTs, and usually their second part too, begin with eyJ.

What's the difference between OAuth and JWT? OAuth is a way to grant an app access. A JWT is a token format. Many OAuth servers issue JWTs as tokens, but OAuth doesn't require them.

Is it safe to put a JWT in localStorage? It's risky. OWASP says not to store session identifiers in local storage because JavaScript can always read it. An httpOnly cookie is safer.

Is my Supabase anon key a JWT? The legacy anon key is a long-lived JWT. The newer publishable key isn't a JWT; Supabase calls it a short string starting with sb_publishable_.

What does JWT stand for? JSON Web Token. RFC 7519 says to pronounce it like the word "jot."

What is a JWT secret? The key used to sign HS256 tokens. Anyone who has it can create valid tokens, so it must stay on your server and never ship to a browser.


A JWT signing secret or service_role key in your frontend is a launch blocker. Run a free scan with Greenlight My App before launch to check your live site's public code for secret key patterns, including Supabase service_role JWTs.

Sources

On this site

Related posts

Supabase is a trademark of Supabase, Inc.; Firebase is a trademark of Google; OWASP is a trademark of the OWASP Foundation. None is affiliated with Greenlight My App. Tokens and keys shown are fake demo values made with a throwaway secret. This page is general information, not professional security advice, legal advice, a security audit or a guarantee. Check your own setup against the vendor's current docs.