Created
January 3, 2019 18:15
-
-
Save ostark/cd521316070304b2bdc3a13ede53e70d to your computer and use it in GitHub Desktop.
passport keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
/* | |
|-------------------------------------------------------------------------- | |
| Encryption Keys | |
|-------------------------------------------------------------------------- | |
| | |
| Passport uses encryption keys while generating secure access tokens for | |
| your application. By default, the keys are stored as local files but | |
| can be set via environment variables when that is more convenient. | |
| | |
*/ | |
'private_key' => base64_decode(env('PASSPORT_PRIVATE_KEY')), | |
'public_key' => base64_decode(env('PASSPORT_PUBLIC_KEY')), | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Laravel\Passport\Passport; | |
class PassportKeysCommand extends Command | |
{ | |
const MAP = [ | |
'PASSPORT_PRIVATE_KEY' => 'privateKey', | |
'PASSPORT_PUBLIC_KEY' => 'publicKey', | |
]; | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'passport:export-keys'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Export keys as base64 encoded'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
list($publicKey, $privateKey) = [ | |
Passport::keyPath('oauth-public.key'), | |
Passport::keyPath('oauth-private.key'), | |
]; | |
if (!(file_exists($publicKey) || !file_exists($privateKey))) { | |
$this->error('Keys do not exist'); | |
return 1; | |
} | |
$this->output->section('Production env vars:'); | |
foreach (self::MAP as $envName => $var) { | |
$value = base64_encode(file_get_contents($$var)); | |
$this->line('<fg=yellow>'.$envName.'</>="'.$value.'"' . PHP_EOL); | |
} | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Console\Commands\PassportKeysCommand; | |
use Illuminate\Support\ServiceProvider; | |
class PassportKeysProvider extends ServiceProvider | |
{ | |
/** | |
* Register services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->commands([ | |
PassportKeysCommand::class | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment