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

Laravel Jwt Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Stateless API authentication where the team wants JWT semantics (self-contained claims, no per-request session store) without adopting Passport's OAuth2 surface area.
  • First-party SPA or server-rendered front ends that terminate auth at the same Laravel app.

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:

  • CSRF. A token carried in a cookie is sent automatically by the browser. If the package reads the cookie for state-changing requests, CSRF protection becomes mandatory (SameSite plus Laravel's CSRF middleware or an equivalent double-submit/header check). This is the single largest risk introduced by the release and must be verified, not assumed — the release note does not state whether CSRF safeguards ship with it.
  • XSS impact escalation. A JWT in an 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.
  • Precedence ambiguity. With two transports, the resolution order (header vs. cookie) is now a behavioral contract. Ambiguity here produces hard-to-diagnose 401s and, worse, silent auth fallbacks.
  • CORS/credentialed requests. Cross-origin SPAs require credentials: 'include' and a non-wildcard Access-Control-Allow-Origin; misconfiguration yields cookie rejection that looks like a token bug.
  • Supply-chain and bus factor. Single-maintainer, low-cadence package with a very small contributor base (one external contributor on this PR). Low lock-in (standard JWT, replaceable), but no vendor SLA.
  • Change-control risk. A small PR-numbered feature shipping in a minor version means the changelog is thin relative to security significance. Consumers must read diffs, not release notes, for auth packages.

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.

  1. Is the cookie HttpOnly, Secure, and SameSite configurable, and what are the defaults? Are values encrypted/signed by Laravel's cookie middleware?
  2. What is the header-vs-cookie precedence, and can it be configured or disabled per guard?
  3. Does the package ship CSRF protection for cookie-authenticated requests, or is that entirely the integrator's responsibility?
  4. Are cookie name, domain, path, TTL, and refresh/rotation behavior configurable? Does rotation rewrite the cookie?
  5. Which Laravel and PHP versions are supported, and is there a test matrix? What is the test coverage for the new cookie path?
  6. Does it remain stateless, or does cookie support imply any session or server-side storage?
  7. What is the release cadence and security-disclosure process for the project?

Integration Approach

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.

  1. Pin and pilot. Pin ~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.
  2. Header-first. Ship header-based auth as the baseline; do not enable cookie transport in the same change. This isolates the variable.
  3. Cookie enablement behind a flag. Introduce cookie transport as a config toggle on a second, isolated change, scoped to a first-party front end only.
  4. Front-end contract. Agree with the client team on credentials: 'include', cookie attributes, CSRF header exchange, logout/clear behavior, and expiry/refresh UX before code lands.
  5. Dual-run window. Run the new guard alongside the incumbent auth for a bounded period with metric comparison (401 rate, refresh rate, auth latency) before cutting over.

Compatibility considerations.

  • Laravel version support and test matrix for the cookie code path specifically.
  • Cookie encryption settings (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.
  • CORS configuration must allow credentials and an explicit origin; verify preflight behavior.
  • Long-running workers (Octane, queue workers) should not cache config or token state inappropriately.
  • Header parsing and cookie parsing must behave identically across load balancers and proxies; confirm 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.

Operational Impact

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.

  • Cookie not sent due to SameSite or third-party-cookie blocking — presents as intermittent 401 in specific browsers only.
  • CORS misconfiguration causing credentialed requests to be dropped.
  • CSRF token mismatch (419) after a token rotation or a stale tab.
  • Header-vs-cookie precedence causing one client to authenticate as a stale identity.
  • Clock skew invalidating nbf/exp; mitigate with NTP discipline and a small leeway.
  • Secret rotation invalidating all live tokens simultaneously — needs a coordinated, communicated rollout.
  • Silent failure when both transports are absent or malformed; ensure error responses are distinguishable in logs without leaking token material.
  • Log leakage: ensure token cookies and 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.

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.
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource