Download the PHP package phithi92/json-web-token without Composer

On this page you can find all versions of the php package phithi92/json-web-token. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-web-token

PHP Version Latest Version

JSON Web Token (JWT) Library

Security-first JWT implementation for PHP 8.2+.
Create, sign, encrypt, decrypt, validate, and reissue JSON Web Tokens with explicit key management and strict defaults.

Supports JWS and JWE, a pluggable algorithm registry, and fine-grained claim validation—without hiding security decisions behind magic defaults.


Highlights


Installation

Requirements


Interoperability

Tokens produced by this library are fully RFC-compliant and interoperable with other JWT implementations across different languages and platforms.

No proprietary headers, claims, or encoding shortcuts are introduced. As long as the same algorithms, keys, and claims are used, tokens can be safely exchanged with other standards-compliant JWT stacks.


Supported RFCs


Architecture Overview

Each component is usable independently, but the default factory wires everything safely for you.


JwtTokenService Default Wiring (createDefault())

JwtTokenServiceFactory::createDefault() is intentionally opinionated and builds a consistent default dependency graph so all operations share the same baseline behavior.

Internally, it creates:

This means:

createTokenWithoutClaimValidation() and decryptTokenWithoutClaimValidation() are intentionally unsafe escape hatches for tests/tooling.


Quick Start

1) Configure Keys / Algorithms

JwtKeyManager holds all keys in memory. Asymmetric keys must be PEM-encoded. Symmetric secrets (HMAC, dir) live in the passphrase store.

If no kid is provided when issuing tokens, one is derived from the JOSE header (e.g. RS256, RSA-OAEP-256.A256GCM). Make sure the corresponding key is registered under that kid, or pass a kid explicitly.


2) Build a Payload

JwtPayload provides helpers for standard claims and strict validation.

Time-based helper setters such as setIssuedAt() and setExpiration() accept date/time strings, for example:

ℹ️ JWT iat, nbf, and exp are NumericDate values (seconds since Unix epoch in UTC). Always generate and compare timestamps in UTC to avoid timezone drift.

If you want to set UNIX timestamps directly, use setClaimTimestamp():


3) Create & Serialize a Token

You may also issue tokens directly from an array of claims:


4) Read (verify/decrypt) & Validate

For JWS tokens this verifies the signature and reads the payload. For JWE tokens this decrypts and then validates claims.

Claim-Only Validation

⚠️ *WithoutClaimValidation() methods exist only for tests or tooling.

5) Business Rules & Replay Protection

JwtValidator can enforce issuer, audience, private claims and protect against JWT replay attacks via a pluggable JWT ID registry.

jti (JWT ID) Deep Dive

jti is the token identifier claim used to uniquely track a token and support replay prevention.

Validation behavior

Auto-generation behavior during issuing

When issuing via JwtTokenService::createToken() / createTokenFromArray() and the chosen validator has a JTI validator configured:

Practical recommendation:

InMemoryJwtIdValidator

InMemoryJwtIdValidator is a simple, deterministic implementation intended for tests, demos, and short‑lived processes.

How useAllowList works

When a token is successfully validated, the service can deny its JWT ID to prevent replay:

⚠️ InMemoryJwtIdValidator is process‑local and non‑persistent.
Use Redis or PDO validators for production replay protection.

Storage backends for JTI replay protection

6) Refresh / Reissue Tokens

The original bundle remains untouched.


Error Handling Patterns

When issuing, parsing, decrypting, or validating tokens, prefer catching specific exception types first and only then falling back to a generic handler.

Recommended Mapping (API-friendly)

Security Best Practices for Error Responses


Supported Algorithms

Identifiers map to handlers via resources/algorithms.php.

JWS (signing)

JWE (encryption)

Prefer RSA-PSS for new RSA signatures and AES-GCM for authenticated encryption. Pin algorithms per client.


Security Best Practices


Development


License

Released under the MIT License. See LICENSE.

Support the project

ko-fi image

All versions of json-web-token with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
phpseclib/phpseclib Version ~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phithi92/json-web-token contains the following files

Loading the files please wait ...