laravel/sanctum
Laravel Sanctum provides featherweight authentication for SPAs and simple APIs using token-based and session-based auth. Install it to secure your API routes with minimal configuration.
composer require laravel/sanctum, publish config/migration, add the HasApiTokens trait to the authenticatable model, and register the auth:sanctum guard. The personal_access_tokens table is polymorphic (since v0.2.0), so it supports multiple tokenable models without schema changes; multiple provider support (v2.4.0) covers multi-guard setups. Realistic effort for a competent Laravel team is days, not weeks — issuance endpoint, ability taxonomy, and revocation flow included.CheckAbilities / CheckForAnyAbility). Token-mode clients get long-lived opaque tokens unless we implement expiry and rotation ourselves. Recent releases show active maintenance (Laravel 13 support, PHP 8.4/8.5 compatibility, optional last_used_at tracking, indexes on personal_access_tokens, HMAC password-hash support), but the moderate score and dependents: 0 in the source data are a data-quality flag — validate adoption and CVE history directly against Packagist and the security policy before treating this as a low-scrutiny dependency.composer.json and treat the pair as a single upgrade unit. Watch the PHP floor — v4.2.1 and v4.0.5 added PHP 8.5/8.4 support, so older pins will block runtime upgrades. Config files are published and app-local, so config/sanctum.php drift (stateful domains, guard list, expiration, last_used_at tracking) is a real upgrade hazard — diff it on every major. The text type change for the token name column and the added indexes in v4.2.0/v4.1.2 imply a migration on upgrade; budget for it on large token tables.HasApiTokens and register the guard; wire auth:sanctum onto a single low-risk route as a canary.sanctum:prune-expired scheduled command.config/sanctum.php diffs, migration review, and regression testing of the stateful-domain and CSRF paths. Assign a named owner for the token lifecycle policy — that is our code, not the package's.Sanctum::getAccessTokenFromRequestUsing/authentication callback hooks. last_used_at writes on every request are write amplification — the optional tracking config added in v4.3.0 should be evaluated and likely disabled on high-traffic endpoints. Cookie mode scales with the session store, so Redis sizing becomes the constraint; the CSRF cookie endpoint is cheap but must not be rate-limited into failures.APP_KEY rotation invalidates encrypted cookies and breaks cookie-mode sessions — must be sequenced with a session flush.sanctum:prune-expired is not scheduled and monitored — degrades lookup performance and confuses audit queries.How can I help you explore Laravel packages today?