Passport needs a "personal access client" to issue personal access tokens, and only the seeder created it (production runs migrations, not the seeder), so createToken threw "Personal access client not found". - New idempotent command passport:ensure-personal-client, run by the container entrypoint after the migrations. - The tokens page now shows an error when the server fails instead of doing nothing (es, en, ca). - Tests: the command creates the client once; tokens can be created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
1000 B
PHP
25 lines
1000 B
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Inspiring;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Laravel\Passport\ClientRepository;
|
|
|
|
Artisan::command('inspire', function () {
|
|
$this->comment(Inspiring::quote());
|
|
})->purpose('Display an inspiring quote');
|
|
|
|
// Sin este cliente, Passport no puede emitir Personal Access Tokens (createToken lanza
|
|
// "Personal access client not found"). Idempotente: lo ejecuta el entrypoint en cada
|
|
// arranque, porque en producción no se corre el seeder.
|
|
Artisan::command('passport:ensure-personal-client', function (ClientRepository $clients) {
|
|
$provider = config('auth.guards.api.provider');
|
|
|
|
try {
|
|
$clients->personalAccessClient($provider);
|
|
$this->info('Personal access client: ya existe.');
|
|
} catch (RuntimeException) {
|
|
$clients->createPersonalAccessGrantClient('Personal Access Client', $provider);
|
|
$this->info('Personal access client: creado.');
|
|
}
|
|
})->purpose('Crea el cliente de Personal Access Tokens si no existe');
|