2016-01-15 02:16:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2016-01-15 07:28:34 +00:00
|
|
|
use Illuminate\Support\Str;
|
2017-12-03 16:54:11 +00:00
|
|
|
use Jackiedo\DotenvEditor\Facades\DotenvEditor;
|
2016-01-15 02:16:58 +00:00
|
|
|
|
|
|
|
class GenerateJWTSecret extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The console command name.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name = 'koel:generate-jwt-secret';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Set the JWTAuth secret key used to sign the tokens';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
2016-08-16 15:12:35 +00:00
|
|
|
*
|
2016-08-16 15:12:11 +00:00
|
|
|
* @throws \RuntimeException
|
2016-01-15 02:16:58 +00:00
|
|
|
*/
|
2017-12-03 16:54:11 +00:00
|
|
|
public function handle()
|
2016-01-15 02:16:58 +00:00
|
|
|
{
|
2017-12-03 16:54:11 +00:00
|
|
|
if (config('jwt.secret')) {
|
|
|
|
$this->comment('JWT secret exists -- skipping');
|
2016-01-15 02:16:58 +00:00
|
|
|
|
2017-12-03 16:54:11 +00:00
|
|
|
return;
|
2016-01-15 02:16:58 +00:00
|
|
|
}
|
2016-01-31 13:46:05 +00:00
|
|
|
|
2017-12-03 16:54:11 +00:00
|
|
|
$this->info('Generating JWT secret');
|
|
|
|
DotenvEditor::setKey('JWT_SECRET', Str::random(32))->save();
|
2016-01-15 02:16:58 +00:00
|
|
|
}
|
|
|
|
}
|