firebase/php-jwt
A simple PHP library to encode and decode JSON Web Tokens (JWT), conforming to RFC 7519. Specify supported algorithms, verify tokens with Key objects, and set leeway for clock skew between servers.
firebase/Google org — so no engineering time goes into hand-rolling crypto. The build-vs-buy decision left for the PM is the identity layer above it (token issuance, revocation, key management, policy), not the encoder.iss/aud/exp is exactly this library's job. This directly gates "Enterprise plan" pricing and sales-cycle decisions.kid-based key maps and CachedKeySet (fetch + cache + rate-limit JWKS from a URI, auto-refresh on unknown kid) make "can we rotate signing keys without downtime?" a config decision rather than a project.leeway knob (clock skew) is a real, user-visible support-cost lever in mobile deployments.Adopt when:
kid-based key selection plus cached JWKS fetching.Key value object, explicit exception taxonomy, leeway for clock skew, and no framework coupling. It wraps cleanly in a Laravel service provider and is trivially testable.Look elsewhere or add scope when:
phpseclib/phpseclib (OpenSSL in PHP doesn't do RSASSA-PSS), or EdDSA without libsodium/sodium_compat. Soft dependencies are still dependencies to review.lcobucci/jwt for a stricter object-oriented API and a formal validation pipeline; Laravel Sanctum if opaque, revocable tokens are actually the right product answer and JWT was only a reflex.Diligence notes before sign-off: the "Dependents: 0" figure in the sourcing is a data-capture gap, not evidence of low adoption — Packagist download volume and ecosystem presence contradict it, so validate via your own dependency graph rather than trusting the metric. Release cadence appears active (2026-09-28), with README, changelog, and releases present, but pin a version and review the changelog at each bump.
To executives (one paragraph): This is free, permissively licensed, standards-based plumbing for authentication tokens, maintained under Google's Firebase org and used across the PHP ecosystem. Adopting it removes weeks of security-sensitive custom work from any SSO, API, or partner-integration initiative, and it avoids both paid auth vendors and proprietary token formats. The real decision it forces is not "which library" but "how much identity infrastructure we own above it" — token revocation, key rotation, and policy — and that should be scoped explicitly rather than discovered mid-build.
To engineering (summary): composer require firebase/php-jwt. Encode with JWT::encode($payload, $key, $alg, $kid); decode with JWT::decode($jwt, new Key($key, $alg)) or a kid => Key map for rotation. Non-negotiables: enforce a server-side algorithm allowlist (never trust the token's alg header), always verify before reading any claim or header, set JWT::$leeway to a few minutes at most for clock skew, and map the exception taxonomy (ExpiredException, BeforeValidException, SignatureInvalidException, UnexpectedValueException) to distinct 401s so clients can act on exp vs. bad signature. Use CachedKeySet with a PSR-6 pool for third-party JWKS — it handles key rotation and rate-limits to 10 RPS. JWT::decode returns stdClass; cast deliberately. Keep payloads minimal — they are readable, not encrypted.
Scope the following as our work, not the library's: signing-key generation and custody, rotation runbook and kid discipline, token lifetime policy, revocation strategy if required, observability on verification failures, and an integration test suite that includes expired, tampered, and wrong-algorithm tokens. Budget days for the first integration and a short design review for the key-management story; the library itself is the small part.
How can I help you explore Laravel packages today?