I want to integrate ckfinder with my laravel but I am stuck with authentication.
I found many ways but there were for older laravel versions and none are working for 5.6.
I found this:
require '../../vendor/autoload.php';
$app = require_once '../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
But I am getting Invalid request from Ckfinder when I put it in config.php
I would like to access Auth::check() and return it in authentication
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
EDIT
So I had a look at index.php and copied this into config.php:
define('LARAVEL_START', microtime(true));
require '/Applications/MAMP/htdocs/laravel-dealer/vendor/autoload.php';
$app = require_once '/Applications/MAMP/htdocs/laravel-dealer/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
But I am getting runtime exceptions for $acl argument.
Fatal error: Uncaught RuntimeException: Controller "CKSource\CKFinder\Command\Init::execute()" requires that you provide a value for the "$acl" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. in /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php:78 Stack trace: #0 /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(141): Symfony\Component\HttpKernel\Controller\ArgumentResolver->getArguments(Object(Symfony\Component\HttpFoundation\Request), Array) #1 /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(66): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #2 /Applications/MAMP/htdocs/laravel-dealer/public/ckfinder/core/connector/php/vendor/cksource/ckfinder/src/CKSource/CKFinder/CKFinder.php(610): Symfony\Component\HttpKernel\HttpKernel- in /Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php on line 78
Thanks for any help
Well I spent some time with this and came up with this solution:
This function gets the value of $_COOKIE['allowCkfinder']
and decrypts it using cipher and your app key.
// /public/ckfinder/config.php
$config['authentication'] = function () {
$APP_KEY = "YOUR_APP_KEY";
$cookie_contents = json_decode( base64_decode( $_COOKIE['allowCkfinder'], true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
return unserialize( openssl_decrypt($value, "AES-256-CBC", base64_decode($APP_KEY), OPENSSL_RAW_DATA, $iv));
};
When logging in user / admin set cookie with name allowCkfinder: Also dont forget to remove the cookie on user logout.
// /app/Http/Controllers/LoginController.php
if (Auth::attempt(['user_email' => $validatedData['email'], 'password' => $validatedData['password'], "user_active" => 1, "user_banned" => 0]))
{
if (Auth::user()->user_admin == TRUE)
return redirect()->intended('/')->withCookie(cookie()->forever('allowCkfinder', "1"));
else
return redirect()->intended('/');
} else
{
$request->session()->flash('error', __("E-mail and/or password do not match"));
return redirect('login')->withInput();
}
That's the best I came up with.