joy/voyager-api-auth
Adds API authentication to Laravel's Voyager admin panel. Protects Voyager admin routes and resources for API clients, SPAs, and mobile apps, extending built-in admin auth to JSON requests so you can avoid building separate authentication plumbing.
vendor/joy/voyager-api-auth/composer.json under extra.laravel.providers:
composer require joy/voyager-api-auth
php artisan vendor:publish
php artisan migrate
php artisan route:list --path=api
vendor/joy/voyager-api-auth/src for controllers, routes, middleware, and config keysREADME.md and composer.json for supported Laravel/Voyager versions and auth driverconfig/ after publishing for guard, token, route-prefix, and model settingsroutes/api.php or the package route files to confirm actual endpointsphp artisan route:list, then test:
POST /api/auth/login
Content-Type: application/json
{"email":"[email protected]","password":"secret"}
Use the returned token as Authorization: Bearer <token> against the package’s me/profile route or your own protected routes.Treat the package as the auth layer, not the whole API. Keep your business endpoints in application routes and protect them with the same guard/token driver the package uses.
Route::middleware(['api', 'auth:sanctum'])
->prefix('v1')
->group(function () {
Route::get('/profile', [ProfileController::class, 'show']);
});
If the package uses Passport or JWT instead of Sanctum, replace auth:sanctum with the corresponding middleware after checking config/auth.php and the package config.
Standardize the client workflow around login, current user, refresh/renew if supported, and logout/revoke:
Integrate Voyager roles/permissions rather than inventing a parallel authorization system. Use Voyager’s user model, roles, and permissions to gate API actions through middleware, policies, or gates. Keep the API guard/provider aligned with the Voyager user provider in config/auth.php.
Customize at the edges first:
AuthController wrapper if the package’s endpoints are too rigid for mobile/SPA requirements.Add operational middleware around the package’s login route: throttle, CORS, JSON error handling, and request logging. The package may provide the auth mechanics but not production hardening.
Test the full flow in feature tests: create a Voyager user, call login, assert token/JSON shape, call a protected route with the token, then assert logout/revocation. For routes that only need authentication, actingAs($user, 'api') is usually faster than generating real tokens.
composer.json constraints against your Laravel, Voyager, PHP, and auth-driver versions before adopting it.personal_access_tokens, Passport keys, or JWT secrets typically show up as 500s on login or 401s on protected routes.web guard and its own user provider. The API package may expect an api guard or a specific user model. Align config/auth.php, config/voyager.php, and the package config; otherwise login succeeds but authenticated requests resolve the wrong user or fail.php artisan vendor:publish interactively and diff the generated files. Clear caches after installation:
php artisan config:clear
php artisan route:clear
php artisan cache:clear
routes/api.php, Voyager routes, or other auth packages. Use php artisan route:list -v to see middleware, guards, and controller actions.MAIL_MAILER=log before relying on them in production.route:list, php artisan about, Laravel logs, and temporary logging in published controllers. If the package is too opaque, replace its auth controller with a small application-owned controller using the same guard and token driver.vendor/ files.How can I help you explore Laravel packages today?