Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

JSON Web Token (JWT)

A JSON Web Token (JWT) is a compact, URL-safe token format defined in RFC 7519, used to securely transmit claims between parties as a JSON object, often signed (JWS) or encrypted (JWE).
Chainscore © 2026
definition
AUTHENTICATION STANDARD

What is JSON Web Token (JWT)?

A JSON Web Token (JWT) is an open, industry-standard method for securely transmitting information between parties as a compact, URL-safe JSON object.

A JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact, URL-safe means of representing claims to be transferred between two parties. It is a digitally signed or encrypted token that is typically used for authentication and authorization. A JWT is composed of three Base64Url-encoded segments separated by periods: a header (specifying the token type and signing algorithm), a payload (containing the claims), and a signature (which verifies the token's integrity). This structure allows the token to be self-contained, meaning all necessary information is embedded within it.

The payload of a JWT contains statements about an entity (typically the user) and additional metadata, known as claims. Standard claims include the issuer (iss), subject (sub), expiration time (exp), and audience (aud). JWTs are commonly used in modern web architectures, such as OAuth 2.0 and OpenID Connect flows, where they serve as access tokens or ID tokens. Because they are stateless, they reduce the need for the server to maintain a session store, making them highly scalable for distributed systems and microservices.

JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair (using RSA or ECDSA). A signed JWT is known as a JWS (JSON Web Signature). They can also be encrypted to ensure confidentiality, resulting in a JWE (JSON Web Encryption). It is critical to implement JWTs securely: store them in HttpOnly cookies to prevent XSS attacks, use short expiration times, and never place sensitive data in the payload unless the token is encrypted. Their compact nature makes them ideal for HTTP Authorization headers using the Bearer scheme.

how-it-works
MECHANICS

How a JWT Works

A technical breakdown of the JSON Web Token (JWT) structure, its creation, and its verification process.

A JSON Web Token (JWT) is a compact, URL-safe token that works by encoding a set of claims in a JSON object, which is then cryptographically signed or encrypted to ensure its integrity and authenticity. The token is structured as three distinct, dot-separated parts: the Header, the Payload, and the Signature. The Header specifies the token type (JWT) and the signing algorithm (e.g., HS256 or RS256). The Payload contains the actual claims, such as user identity (sub), issuer (iss), and expiration time (exp). The Signature is generated by signing the encoded header and payload with a secret key or private key, binding them together to prevent tampering.

The process begins with token creation. A server (the issuer) generates the JWT after a user successfully authenticates. It builds the header and payload JSON objects, then Base64Url encodes them. These encoded strings are concatenated with a period. Finally, the server applies the cryptographic algorithm specified in the header to this concatenated string, creating the signature. The final JWT is the combination of [encoded header].[encoded payload].[encoded signature]. This token is then typically sent to the client, often within an HTTP Authorization header using the Bearer scheme.

Token verification is the reverse process performed by a receiving party (the resource server). Upon receiving a JWT, the verifier first splits the token into its three parts. It independently recalculates the signature using the same algorithm and the appropriate secret or public key. If the newly calculated signature matches the one in the token, it proves the token hasn't been altered and was issued by a trusted party. The verifier then decodes the payload to check critical claims, most importantly the expiration time (exp) to reject stale tokens. This stateless verification mechanism is core to JWT's use in distributed systems and API authentication.

JWTs enable stateless sessions because all necessary user data is contained within the token itself, eliminating the need for the server to store session state in a database. Common use cases include Single Sign-On (SSO), where an authentication server issues a JWT that multiple services can independently verify, and securing RESTful APIs between microservices or for mobile applications. It's crucial to implement security best practices, such as using strong algorithms (avoiding none), keeping secrets secure, setting short expiration times, and validating all claims. JWTs are defined by the RFC 7519 standard.

key-features
ARCHITECTURE

Key Features of JWTs

JSON Web Tokens are a compact, URL-safe means of representing claims to be transferred between two parties. Their structure and design enable secure authentication and information exchange.

01

Compact & Self-Contained Structure

A JWT is a compact string composed of three Base64Url-encoded parts separated by dots: Header.Payload.Signature. This structure is self-contained, meaning the payload contains all the required user claims, avoiding the need for repeated database queries during token validation.

  • Header: Specifies the token type (JWT) and the signing algorithm (e.g., HS256, RS256).
  • Payload: Contains the claims—statements about an entity (e.g., user ID, roles, expiration) and additional data.
  • Signature: Ensures the token hasn't been tampered with by signing the encoded header and payload.
02

Stateless Authentication

JWTs enable stateless authentication, a core feature for scalable APIs. The server does not need to store session state or token information. After issuing a signed JWT, the server can validate subsequent requests by verifying only the token's signature and expiry. This eliminates server-side session storage, reduces database load, and simplifies horizontal scaling across multiple servers.

  • The client stores the JWT (typically in local storage or an HTTP-only cookie) and sends it with each request via the Authorization header.
  • The server's validation logic is independent and repeatable for every request.
03

Standardized Claims & Custom Data

JWTs use a standardized set of registered claims defined in the RFC 7519 specification, providing interoperability. Developers can also include public claims or private claims to convey any necessary application-specific data.

Common Registered Claims:

  • sub (subject): The user identifier.
  • exp (expiration time): Unix timestamp for token expiry.
  • iat (issued at): Timestamp of token creation.
  • iss (issuer): Entity that created the token.

Example Payload:

json
{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022,
  "admin": true
}

The admin field is a custom private claim.

04

Signature & Integrity Verification

The signature is the security cornerstone of a JWT. It is created by taking the encoded header, encoded payload, a secret (for HMAC) or a private key (for RSA/ECDSA), and signing them with the algorithm specified in the header. This process guarantees integrity—the recipient can verify that the token content has not been altered—and, when using asymmetric cryptography, authenticates the issuer.

  • HMAC (Symmetric): Uses a single shared secret. Both issuer and verifier must know the secret.
  • RSA/ECDSA (Asymmetric): Uses a private key to sign and a corresponding public key to verify. This is common for distributed systems.
05

Token Types: JWS vs. JWE

JWTs come in two main cryptographic forms, defined by separate RFCs:

  • JWS (JSON Web Signature): The most common type. It provides integrity via a signature but does not encrypt the payload. The payload is Base64Url-encoded but readable by anyone who inspects the token.
  • JWE (JSON Web Encryption): Provides confidentiality by encrypting the payload. The result is a five-part structure. JWE is used when the token must carry sensitive data that should not be visible to clients or intermediaries.

Most authentication flows use signed (JWS), non-encrypted tokens, storing only non-sensitive identifiers in the payload.

06

Common Vulnerabilities & Best Practices

While powerful, JWTs require careful implementation to avoid security pitfalls.

Key Risks & Mitigations:

  • Token Storage: Storing tokens in localStorage is vulnerable to XSS attacks. Prefer HTTP-only cookies for web apps, though this introduces CSRF concerns.
  • Algorithm Confusion: Always explicitly verify the signing algorithm on the server (alg in header) to prevent attackers from forcing a none algorithm or switching from asymmetric to symmetric.
  • Short Expiry & Refresh Tokens: Use short-lived access tokens (minutes) paired with long-lived refresh tokens stored securely server-side to balance security and user experience.
  • Signature Verification: Never decode a JWT without verifying its signature first.
jwt-structure
ARCHITECTURE

JWT Structure: Header, Payload, Signature

A JSON Web Token (JWT) is a compact, URL-safe token format defined in RFC 7519, used to securely transmit claims between parties as a JSON object. Its canonical structure consists of three distinct, base64url-encoded parts separated by dots.

A JSON Web Token (JWT) is a compact, URL-safe token format defined in RFC 7519, used to securely transmit claims between parties as a JSON object. Its canonical structure consists of three distinct, base64url-encoded parts separated by dots: the Header, the Payload, and the Signature, forming the pattern header.payload.signature. This structure enables the token to be both self-contained—carrying all necessary information within itself—and verifiable, ensuring its integrity and authenticity.

The Header (header) typically consists of two parts: the token type, which is always JWT, and the signing algorithm used, such as HS256 (HMAC SHA-256) or RS256 (RSA SHA-256). This metadata, encoded as a JSON object, tells the verifier how to process the signature. The Payload (payload) contains the claims—statements about an entity (typically, the user) and additional metadata. Claims are categorized as registered (standard fields like iss for issuer, exp for expiration), public, or private (custom) claims. It is crucial to note that the payload is only base64url-encoded, not encrypted; sensitive data should never be stored in a JWT.

The Signature (signature) is the cryptographic component that ensures the token's integrity. It is created by taking the encoded header, the encoded payload, a secret (for HMAC) or a private key (for RSA/ECDSA), and signing them using the algorithm specified in the header. The verifier recalculates the signature using the provided header, payload, and the corresponding public key or secret. If the signatures match, it confirms the token was not tampered with and, in the case of asymmetric cryptography, originated from a trusted issuer. This mechanism makes JWTs ideal for stateless authentication in APIs and single sign-on (SSO) systems.

examples
APPLICATIONS

Common Use Cases for JWTs

JSON Web Tokens (JWTs) are a compact, self-contained mechanism for securely transmitting information between parties as a JSON object. Their stateless nature and cryptographic integrity make them ideal for several core authentication and authorization patterns.

04

Secure Information Exchange

JWTs provide a verifiable and tamper-proof container for transmitting data between two parties. Because they are digitally signed (using HMAC or RSA/ECDSA), the recipient can be confident the information has not been altered. This makes them suitable for scenarios like:

  • Email verification links containing a user ID and expiry.
  • Password reset tokens.
  • Passing verified user context between internal microservices in a service mesh.
05

Cross-Domain & Mobile Authentication

JWTs are well-suited for cross-origin scenarios and mobile applications. They can be securely stored in a mobile device's local storage or keychain and attached to requests. For web applications, they avoid the limitations and security concerns of cross-domain cookies. The token's self-contained nature means the client app does not need to manage complex session state, simplifying the architecture for native iOS/Android apps.

ecosystem-usage
AUTHENTICATION & AUTHORIZATION

JWT Usage in the Blockchain Ecosystem

JSON Web Tokens (JWTs) are a compact, URL-safe means of representing claims to be transferred between parties. In blockchain, they are primarily used for off-chain authentication and secure API access to on-chain data and services.

01

Decentralized Identity (DID) Authentication

JWTs are a core component in Decentralized Identity (DID) systems like W3C Verifiable Credentials. A user's wallet signs a JWT with their private key, creating a cryptographic proof of identity that can be verified by any service without contacting a central authority. This enables self-sovereign identity and secure, portable logins across dApps.

  • Structure: The JWT payload contains DID claims (e.g., iss, sub).
  • Verification: The service verifies the signature against the user's public key on the blockchain or a DID document.
02

Secure API & Oracle Access

Blockchain oracles and node providers use JWT-based authentication to control and meter access to their APIs. A client (e.g., a smart contract developer) obtains a JWT from an auth service, which is then included in the header of requests to fetch off-chain data or submit transactions.

  • Authorization: Tokens encode specific permissions (scopes) like read:data or write:tx.
  • Security: Prevents unauthorized use of paid API endpoints and protects against Sybil attacks by tying requests to an identity.
03

Off-Chain Session Management for Wallets

dApp front-ends and wallet connectors use JWTs to manage user sessions without storing sensitive keys in browser storage. After a user signs a message with their wallet (e.g., Sign-In with Ethereum), the backend issues a short-lived JWT session token.

  • User Experience: Allows persistent, authenticated sessions across browser refreshes.
  • Security: The JWT contains a nonce and expiry, reducing the need for constant wallet pop-up signatures and mitigating replay attacks.
04

Verifiable Claims for On-Chain Actions

JWTs can act as verifiable attestations that are submitted to smart contracts. An off-chain trusted issuer (e.g., a KYC provider) signs a JWT containing a user's credential. The user then presents this JWT to a contract, which verifies the issuer's signature on-chain before granting access.

  • Use Case: Gating access to a token sale based on a signed KYC JWT.
  • Challenge: On-chain JWT verification requires libraries (like eth-jwt-verifier) to handle the JSON and signature parsing in Solidity or Vyper.
05

JWT vs. Native Blockchain Signatures

While both provide authentication, they operate in different layers.

  • JWT: A standardized off-chain token format (RFC 7519) for representing claims. It's verified by checking a cryptographic signature, often using the same elliptic curve cryptography (e.g., ES256K) used by blockchains.
  • Native Signature: A raw ECDSA signature (like secp256k1) on a specific message or transaction hash. It's verified directly by the blockchain's EVM or node.

JWTs often wrap a native signature as proof, creating a portable, claim-based credential.

06

Security Considerations & Best Practices

Using JWTs in blockchain contexts introduces specific security requirements.

  • Key Management: The private key used to sign the JWT must be secured with the same rigor as a blockchain wallet key.
  • Expiry & Revocation: Implement short expiry times (exp) and consider mechanisms for token revocation, as JWTs are stateless.
  • Signature Verification: Always verify the signature algorithm (alg header) to prevent algorithm confusion attacks. Reject tokens using none or weak algorithms.
  • Claim Validation: Rigorously validate all standard claims (iss, aud, sub, exp) to ensure the token is intended for your service and is valid.
security-considerations
JSON WEB TOKEN (JWT)

Security Considerations & Best Practices

JSON Web Tokens (JWTs) are a compact, URL-safe means of representing claims between two parties. While powerful for authentication and authorization, their security depends entirely on proper implementation and handling.

01

Signature Validation

The most critical security step is verifying the JWT's signature to ensure it was issued by a trusted party and hasn't been tampered with. Always use a strong signing algorithm like RS256 (asymmetric) over HS256 (symmetric) for server-side validation. Never accept tokens with the alg header set to none.

02

Claim Validation

Never trust the token payload without validation. Essential checks include:

  • exp (Expiration Time): Token must not be expired.
  • nbf (Not Before): Token must be valid for use.
  • iss (Issuer): Token must be from the expected authorization server.
  • aud (Audience): Token must be intended for your application. Missing these checks is a common vulnerability.
03

Secret & Key Management

The security of signed JWTs hinges on protecting the signing key.

  • For HMAC (HS256), the secret must be strong, randomly generated, and stored securely (e.g., in a secrets manager), never in client-side code.
  • For RSA (RS256), protect the private key on the issuer; clients only need the public key for verification. Regularly rotate keys according to a defined policy.
04

Token Storage on Client

Where to store the token client-side is a key decision with security trade-offs:

  • HttpOnly Cookies: Mitigates XSS attacks but requires CSRF protection. Best for web apps.
  • Browser LocalStorage/SessionStorage: Accessible via JavaScript, making tokens vulnerable to XSS. Not recommended for sensitive applications.
  • Secure Mobile Storage: Use platform-specific secure enclaves (Keychain/Keystore). Never store in plaintext.
05

Short Expiry & Refresh Tokens

Use short-lived Access Tokens (e.g., 5-15 minutes) to limit the window of misuse if a token is stolen. Pair them with long-lived Refresh Tokens stored securely server-side to obtain new access tokens. This pattern balances security and user experience. Refresh tokens must be revocable and checked against a blocklist.

06

Common Vulnerabilities

Be aware of these frequent attack vectors:

  • Algorithm Confusion: Attackers force a switch from RS256 to HS256 by tampering with the alg header.
  • JWT Forgery: Modifying the payload without invalidating the signature (possible if the alg is set to none).
  • Information Leakage: Sensitive data should not be placed in the token payload, as it is easily decoded (Base64Url).
AUTHENTICATION MECHANISMS

JWT vs. Session Tokens vs. Opaque Tokens

A comparison of stateless, stateful, and reference-based token architectures for API and web authentication.

Feature / CharacteristicJSON Web Token (JWT)Session Token (Stateful)Opaque Token (Reference)

Token Structure

Self-contained JSON payload (Header.Payload.Signature)

Cryptographically random string (no intrinsic data)

Cryptographically random string (no intrinsic data)

State Management

Stateless (server validates signature)

Stateful (server stores session data)

Stateful (server stores token binding)

Data Payload

Server-Side Storage Required

Immediate Revocation

Default Validation Overhead

Signature verification only

Database/ cache lookup

Database/ cache lookup

Scalability Impact

Horizontal scaling is trivial

Requires shared session store or sticky sessions

Requires shared token store

Common Use Cases

API authentication, short-lived claims

Traditional web app sessions, user state

OAuth 2.0 bearer tokens, refresh tokens

JSON WEB TOKEN (JWT)

Frequently Asked Questions (FAQ)

A JSON Web Token (JWT) is a compact, URL-safe token standard for securely transmitting claims between parties. These FAQs address its core mechanics, security, and application in modern authentication and authorization systems.

A JSON Web Token (JWT) is a compact, URL-safe token standard (RFC 7519) for securely transmitting claims between two parties, typically used for authentication and authorization. It works by encoding a set of claims in a JSON object, which is then digitally signed or encrypted. A JWT consists of three Base64Url-encoded parts separated by dots: the Header (specifying token type and signing algorithm), the Payload (containing the claims), and the Signature (for verification). The server signs the header and payload with a secret or private key, and the client presents this token in subsequent requests to prove its identity and permissions without requiring server-side session storage.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team
JSON Web Token (JWT) - Definition & Use Cases | ChainScore Glossary