rcerljenko/laravel-jwt
A lightweight JWT authentication package for Laravel. It provides a guard, middleware, and token helpers for issuing, validating, and refreshing JSON Web Tokens, making it easy to secure APIs with stateless authentication. Simple setup and Laravel-friendly configuration.
Context. This is the first formal assessment; no prior baseline exists. The data available is limited to the 2.1.0 release note ("Added support for token via cookie", PR #2, contributed by @ashraful1971). Conclusions below are therefore directional and should be confirmed against the package source, composer.json constraints, and test coverage before commitment.
Architecture fit. rcerljenko/laravel-jwt is a thin JWT authentication layer that plugs into Laravel's native auth system (custom guard driver + middleware + config file), rather than a full OAuth2/authorization server. That makes it a good architectural fit for:
It is a poor fit if the roadmap includes third-party clients, scopes/consent, refresh-token grant semantics, or delegated authorization — those are Passport/Sanctum territory, and retrofitting them later is a rewrite of the auth boundary, not a config change.
Integration feasibility. Low-to-moderate. The expected path is: composer require, publish config, register the guard in config/auth.php, add middleware to route groups, and point login at the package's token issuance. The 2.1.0 cookie transport is a config-level addition rather than an API change, so it should be adoptable incrementally. Real effort sits in the security review and in front-end coordination, not in the install.
Technical risk. 2.1.0 is not a breaking change, but it materially expands the threat surface and should be treated as a security-relevant feature, not a convenience toggle:
Authorization header is not readable by injected script in the same way a non-HttpOnly cookie is. Whether the cookie is HttpOnly/Secure/SameSite and whether it is encrypted by Laravel's cookie middleware must be confirmed in source.credentials: 'include' and a non-wildcard Access-Control-Allow-Origin; misconfiguration yields cookie rejection that looks like a token bug.Recommendation. Adopt 2.1.0 only for header-based usage now; treat cookie transport as opt-in and gated behind a security review. If the product needs cookie-based sessions for a first-party SPA, evaluate Sanctum first — it solves the same problem with first-party maintenance and built-in CSRF/stateful-domain handling.
Key questions.
HttpOnly, Secure, and SameSite configurable, and what are the defaults? Are values encrypted/signed by Laravel's cookie middleware?Stack fit. Compatible with a conventional Laravel API or monolith on a supported PHP 8.x runtime, deployed behind Nginx/ALB or similar. It composes with existing Laravel middleware (CORS, CSRF, throttling) rather than replacing them. It is not additive to Sanctum or Passport — running two auth guards for the same surface creates token-format confusion and duplicated middleware. Pick one primary guard per surface and be explicit about it.
Decision gate before migration. Confirm the package's declared Laravel/PHP constraints against the target app. If the app is on a Laravel major the package does not test against, that alone should block adoption regardless of the cookie feature.
Migration path.
~2.1.0 (or a locked hash) and integrate on a single non-customer-facing service or internal API to validate guard behavior, error responses, and middleware ordering.credentials: 'include', cookie attributes, CSRF header exchange, logout/clear behavior, and expiry/refresh UX before code lands.Compatibility considerations.
EncryptCookies middleware) and any interaction with API route groups that normally skip the web middleware stack — a token cookie set on a web route but read on an api route needs deliberate middleware coverage.TrustProxies and secure-cookie detection.Sequencing. Pin → pilot on internal service → header-only rollout → security review of cookie path → cookie rollout behind flag to one front end → dual-run metrics → deprecate incumbent path. Budget a security review as a discrete milestone, not a checkbox at the end.
Maintenance. Low ongoing code maintenance, but non-trivial attention maintenance: a small-maintainer auth dependency requires someone to read diffs on every release, because minor versions can carry security-relevant behavior. Assign a named owner and a monthly review cadence. Keep a documented exit plan (JWT is standard; swapping in Sanctum or a hand-rolled guard is a bounded, well-understood effort) so the bus-factor risk is priced rather than ignored.
Support. Community-only. No vendor escalation, no SLA. Internal runbook must cover: rotating signing keys/secrets, forcing global token invalidation, diagnosing 401 vs. 419 (CSRF) vs. CORS failures, and clearing the auth cookie on logout and on suspected compromise. Document the token lifetime and refresh policy in one place — this is the most common source of "why did I get logged out" tickets.
Scaling. Effectively stateless with header auth, so horizontal scaling is trivial — no shared session store required. Caveats: any blacklist/revocation mechanism reintroduces a shared datastore and a per-request lookup; cookie transport adds no server cost but does add browser-side constraints (cookie size limits, per-domain cookie counts, cross-site cookie blocking in privacy-focused browsers and Safari ITP). Token size matters if the claim set grows.
Failure modes to pre-plan.
SameSite or third-party-cookie blocking — presents as intermittent 401 in specific browsers only.nbf/exp; mitigate with NTP discipline and a small leeway.Authorization headers are redacted in access logs and APM traces.Ramp-up. A competent Laravel developer can integrate the package in well under a day; the cookie path adds perhaps another day including tests. Realistic elapsed time is 1–2 weeks end-to-end once front-end coordination, CORS/CSRF hardening, and security review are included. Onboarding cost for the team is low — the package surfaces standard JWT concepts — but the operational knowledge (rotation, revocation, cookie attributes) should be written down rather than held by one engineer.
How can I help you explore Laravel packages today?