d076/sanctum-refresh-tokens
Add refresh token support to Laravel Sanctum. Issue short-lived access tokens alongside revocable refresh tokens, rotate them on use, and keep API authentication secure without long-lived tokens.
AuthService::refresh() previously reset token abilities to ['*'], silently widening a scoped token to full permissions on every refresh. Any roadmap item that depends on least-privilege tokens — third-party integrations, partner APIs, per-client permissions, read-only tokens, multi-tenant delegation — was effectively unsafe before this version. Scopes now live on the refresh token and survive refreshes and access-token pruning, which makes those features viable.LICENSE, a rewritten README, a real test suite, and static analysis reduce the paperwork in procurement and security review. This is the kind of thing that shortens a vendor questionnaire from weeks to days.getUserFromCredentials() fix (calling getEmailField() on a class-string, fatal for models with a custom email column) unblocks teams whose user model doesn't use a plain email column — a common setup for multi-identifier or SSO-adjacent products.Adopt when:
Look elsewhere — or stay put — when:
Before committing, confirm the upgrade cost on your side: the new abilities column requires a migration on personal_refresh_tokens, the three newly declared dependencies (illuminate/auth, illuminate/notifications, laravel/framework) should be checked against your lockfile, and existing refresh tokens issued under v3 will not carry persisted abilities — decide whether to invalidate them or grandfather them.
For executives: This is a small, MIT-licensed dependency that removes a category of self-inflicted security risk from our auth stack. The v4 release fixes a privilege-escalation flaw where a narrowly scoped token could silently regain full permissions on refresh — the kind of defect that becomes a customer-facing incident. It also arrives with automated tests, static analysis, multi-database verification, and a clear license, which lowers our compliance and review overhead. Cost is zero; the main commitment is a scheduled upgrade window because the release drops older framework and PHP support. Recommendation: adopt v4 and align the upgrade with our Laravel 13 migration rather than running them as separate projects.
For engineering: v4 persists abilities on personal_refresh_tokens via a new migration, so scope survives refresh and access-token pruning — that closes the ['*'] widening bug and lets us build scoped tokens safely. It also fixes getUserFromCredentials() resolving getEmailField() on a class-string, which fatals for custom email columns. Breaking changes are explicit: Laravel 11 dropped (^12.0|^13.0), PHP floor raised to 8.3, and illuminate/auth, illuminate/notifications, and laravel/framework are now declared rather than assumed. The repo gains a Pest + Orchestra Testbench suite, cross-database CI, a PHP 8.3/8.4/8.5 × Laravel 12/13 matrix, PHPStan level 6, .gitattributes to keep dev files out of the dist archive, and a rewritten README. Plan the migration, decide the disposition of pre-existing refresh tokens, and re-run our auth integration tests against Postgres and MySQL, not just SQLite.
How can I help you explore Laravel packages today?