1

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

DeiForm
  • 701
  • 9
  • 31

2 Answers2

-1

Here's how the authentication section looks like on one of my projects

/*============================ Enable PHP Connector HERE ==============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_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();
};  
Tudor
  • 1,798
  • 2
  • 12
  • 21
  • I get this error: 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. – DeiForm Mar 19 '18 at 14:56
  • Have you changed anything else on your ckfinder installation or in the config file? I feel this shouldn't be caused by the authentication code. Can you try using a fresh install of ckfinder and just paste in the auth code for starters? – Tudor Mar 19 '18 at 15:06
  • now I get uknown error from ckfinder. Well I jsut copied / paste your code. Check updated question – DeiForm Mar 19 '18 at 15:12
  • When I dump this: var_dump(auth()->check()); it says true so I am confused, maybe I need to exclude ckfinder from htaccess rewrites? – DeiForm Mar 19 '18 at 15:13
  • but in ckfinder errors it says again the same about the $acl – DeiForm Mar 19 '18 at 15:15
  • 1
    you get a conflict with ckfinder Symfony and laravel Symfony thats why you get acl – ddjikic Apr 11 '18 at 16:24
-1

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.

DeiForm
  • 701
  • 9
  • 31