Create keys by hand if not existing.

This commit is contained in:
James Cole 2018-04-02 15:26:33 +02:00
parent 8c024a1ae9
commit d48fb3ba55
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -40,7 +40,9 @@ use Google2FA;
use Hash;
use Illuminate\Contracts\Auth\Guard;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Passport;
use Log;
use phpseclib\Crypt\RSA;
use Preferences;
use Session;
use View;
@ -202,7 +204,12 @@ class ProfileController extends Controller
public function index()
{
// check if client token thing exists (default one)
$count = DB::table('oauth_clients')->whereNull('user_id')->count();
$count = DB::table('oauth_clients')
->where('personal_access_client', 1)
->whereNull('user_id')->count();
$this->createOAuthKeys();
if ($count === 0) {
/** @var ClientRepository $repository */
$repository = app(ClientRepository::class);
@ -415,6 +422,28 @@ class ProfileController extends Controller
return true;
}
/**
*
*/
private function createOAuthKeys()
{
$rsa = new RSA();
$keys = $rsa->createKey(4096);
[$publicKey, $privateKey] = [
Passport::keyPath('oauth-public.key'),
Passport::keyPath('oauth-private.key'),
];
if (file_exists($publicKey) || file_exists($privateKey)) {
return;
}
Log::alert('NO OAuth keys were found. They have been created.');
file_put_contents($publicKey, array_get($keys, 'publickey'));
file_put_contents($privateKey, array_get($keys, 'privatekey'));
}
/**
* @return string
*/