laravel/airlock
Laravel Sanctum (formerly Airlock) provides a lightweight authentication system for Laravel SPAs and simple APIs, offering first-party SPA cookie auth plus API token issuing and management for users, mobile apps, and third-party clients.
HasApiTokens trait, Sanctum guard).stateful configuration allows SPAs to use session-like behavior without traditional sessions.tokenCan()) aligns with security best practices. Recent optimizations (e.g., indexed personal_access_tokens table) improve performance for high-scale use cases.personal_access_tokens), which is lightweight and non-intrusive. No complex schema changes are required.EnsureFrontendRequestsAreStateful, Authenticate). Existing middleware can be extended or overridden.getAccessTokenFromRequestUsing() to customize token extraction (e.g., from headers, query params).createToken() or use HasApiTokens trait for custom token logic.sanctum + api), enabling granular auth logic.Authorization: Bearer headers.localStorage in SPAs) is inherent to stateless auth. Mitigation: Use short-lived tokens + stateful mode for SPAs.EnsureFrontendRequestsAreStateful middleware to validate X-Requested-With headers.personal_access_tokens) address this. Benchmark with expected load.crc32b).HasApiTokens trait), reducing coupling.localStorage; prefer HttpOnly cookies (stateful) or secure token managers.HasApiTokens trait supports this, but testing is required.HasApiTokens trait for user/token relationships.routes config).fetch/axios with Authorization headers or stateful cookies.text column for token names).HasApiTokens (v4+), but requires testing.composer require laravel/sanctum).php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider").config/sanctum.php:
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost,127.0.0.1,.yourspa.com')),
'expiration' => null, // Or set TTL (e.g., now()->addDays(14))
'middleware' => ['web', 'api'], // Adjust as needed
php artisan vendor:publish --tag="sanctum-config" --tag="sanctum-migrations"
fetch/axios.How can I help you explore Laravel packages today?