Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Jwt Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy on identity primitives. JWT signing/verification is commodity infrastructure. This package is the "buy" (adopt) answer — a spec-conformant RFC 7519 implementation maintained under the 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.
  • SSO / enterprise-tier roadmap. Enterprise buyers ask for SSO (SAML is expensive; OIDC is cheap). Decoding OIDC ID tokens and validating iss/aud/exp is exactly this library's job. This directly gates "Enterprise plan" pricing and sales-cycle decisions.
  • API platform and partner integrations. Any public API, webhook consumer, or partner handshake that speaks JWT (Google IAP, Firebase Auth, Auth0, Okta, Apple Sign In, marketplace app tokens) can be verified in-house instead of buying a third-party verification service. Expands the list of integrations we can ship without procurement.
  • Architecture: stateless vs. stateful auth. Choosing JWTs (self-contained, verifiable by any service, no shared session store round-trip) vs. opaque tokens/sessions (revocable, simpler). This package lowers the cost of the stateless path — worth knowing before committing to a revocation-heavy design that JWTs make awkward.
  • Multi-service / microservice authentication decisions. Encode with a private key, distribute the public key, services verify independently — removes a per-request auth call to a central service. A latency and blast-radius argument, not just a code argument.
  • Key rotation and multi-tenant strategy. 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.
  • Mobile/SPA token strategy. Short-lived access tokens with client-side storage trade-offs; the leeway knob (clock skew) is a real, user-visible support-cost lever in mobile deployments.
  • Time-to-market for any "log in with / authenticate against X" feature. Typically days of integration work rather than a quarterly initiative, which changes how aggressively these land on a roadmap.

When to Consider This Package

Adopt when:

  • The stack is PHP/Laravel and any service needs to issue or verify a standards-compliant JWT. Laravel has no first-party JWT support, so a library is required regardless; this is the lowest-friction, framework-agnostic choice.
  • You are a relying party verifying tokens minted elsewhere (OIDC providers, Firebase, Google IAP, partner platforms) and need kid-based key selection plus cached JWKS fetching.
  • You need asymmetric algorithms (RS256/ES256/EdDSA) for service-to-service auth where verifiers must not hold signing secrets, or HS256 for a single-trusted-backend case.
  • You want a small, stable dependency surface: one class plus a 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.
  • You value the license: BSD-3-Clause — permissive, no copyleft review, safe for commercial and closed-source distribution.

Look elsewhere or add scope when:

  • You need encrypted tokens (JWE). This is JWS only. Confidential claims must not ride in a JWT payload — anything base64url-encoded is readable by the client. Design accordingly or pick a different tool.
  • You need an OAuth2 / OIDC server. This is a token codec, not an authorization server. That's a different (and much larger) buy.
  • Revocation is a hard requirement. There is no revocation list, no session store, no refresh-token lifecycle. You must build a denylist/jti store or keep token lifetimes short — a design constraint to surface before committing, not after.
  • You need PS256 without adding phpseclib/phpseclib (OpenSSL in PHP doesn't do RSASSA-PSS), or EdDSA without libsodium/sodium_compat. Soft dependencies are still dependencies to review.
  • You need vendor SLA, indemnification, or commercial support. BSD-3 gives you the code and nothing else; maintenance depends on volunteer/Google bandwidth, not a contract.
  • A more opinionated alternative fits better: 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.
  • Team is not on PHP. Obvious, but worth stating: this is a stack-local decision, and mixing token formats across stacks costs more than it saves.

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.

How to Pitch It (Stakeholders)

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums