diff --git a/src/Console/ClientCommand.php b/src/Console/ClientCommand.php index a312a401e..f51a6b08f 100644 --- a/src/Console/ClientCommand.php +++ b/src/Console/ClientCommand.php @@ -162,6 +162,6 @@ protected function createAuthCodeClient(ClientRepository $clients) protected function outputClientDetails(Client $client) { $this->line('Client ID: '.$client->id); - $this->line('Client secret: '.$client->secret); + $this->line('Client secret: '.$client->plainSecret); } } diff --git a/src/Console/HashCommand.php b/src/Console/HashCommand.php new file mode 100644 index 000000000..69f83e9aa --- /dev/null +++ b/src/Console/HashCommand.php @@ -0,0 +1,55 @@ +warn("Please enable client hashing yet in your AppServiceProvider before continuning."); + + return; + } + + if ($this->confirm('Are you sure you want to hash all client secrets? This cannot be undone.')) { + $model = Passport::clientModel(); + + foreach ((new $model)->whereNotNull('secret')->cursor() as $client) { + if (password_get_info($client->secret)['algo'] === PASSWORD_BCRYPT) { + continue; + } + + $client->timestamps = false; + + $client->forceFill([ + 'secret' => password_hash($client->secret, PASSWORD_BCRYPT), + ])->save(); + } + + $this->info('All client secrets were successfully hashed.'); + } + } +} diff --git a/src/PassportServiceProvider.php b/src/PassportServiceProvider.php index 02cf5a389..44900b2d4 100644 --- a/src/PassportServiceProvider.php +++ b/src/PassportServiceProvider.php @@ -62,6 +62,7 @@ public function boot() $this->commands([ Console\InstallCommand::class, Console\ClientCommand::class, + Console\HashCommand::class, Console\KeysCommand::class, Console\PurgeCommand::class, ]);