2

I'm using Laravel 5. I have folder that references ckfinder in /public/plugins/ckfinder directory.

CheckAuthentication function in config.php is I need to use but session value and Auth Class is null.

I have tried

function CheckAuthentication(){
    return Auth::check();
}

or

 //Ckfinder Config.php
function CheckAuthentication(){
        if($_SESSION['ckfinder_enabled'] == 'enabled') {
            return true;
        } else {
            return false;
        }
    }

 

        //App\Http\Middleware\Authenticate.php
    public function handle($request, Closure $next)
            {
                if ($this->auth->guest()){
                        if ($request->ajax()){
                            return response('Unauthorized.', 401);
                        }else{
                            return redirect()->guest('auth/login');
                        }
                    }

                if($this->auth->check()) {
                     $_SESSION['ckfinder_enabled'] = 'enabled';
                    return $next($request);
                }
            }
bugraguney
  • 43
  • 1
  • 5

3 Answers3

5

I had the same issue too. Your code is useful for laravel 4.2 but for laravel 5 you need to do this in ckfinder folder's config.php:

require _DIR_.'/../../../bootstrap/autoload.php';
$app = require_once _DIR_.'/../../../bootstrap/app.php';

$app->make('Illuminate\Contracts\Http\Kernel')
  ->handle(Illuminate\Http\Request::capture());

Then you are ready to go with this code:

function CheckAuthentication(){
    return Auth::check();
}

This should work.

Ecehan Ece
  • 98
  • 9
0

Laravel 5.7+:

require  $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
$app = require_once  $_SERVER['DOCUMENT_ROOT']. '/../bootstrap/app.php';
$response = $app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
$cookie = $_COOKIE[$app['config']['session']['cookie']] ?? false;
if ($cookie) {
    $id = $app['encrypter']->decrypt($cookie, false);
    $session = $app['session']->driver();
    $session->setId($id);
    $session->start();
}

if (!$app['auth']->check()){
    header('HTTP/1.0 403 Forbidden'); exit();
}
  • Does not work on Laravel 5.8. The CLI throws up this error "Call to a member function make() on boolean" in config/ckfinder.php and all stopped. – extensa5620 Jul 09 '19 at 10:30
  • Finally found a working solution for my Laravevl 5.8 project. Thank you so much – Afif Zafri Jun 15 '20 at 06:09
0

CKFinder 3 for PHP

Laravel v7.30.4

works for me

use Illuminate\Support\Facades\Auth;

$config['authentication'] = function () {
  require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
  $app = require_once  $_SERVER['DOCUMENT_ROOT']. '/bootstrap/app.php';
  $request = Illuminate\Http\Request::capture();
  $request->setMethod('GET');
  $app->make('Illuminate\Contracts\Http\Kernel')->handle($request);
  if (Auth::check() && Auth::user()->is_admin ) {
    return true;
  } else {
    header('HTTP/1.0 403 Forbidden');
    exit();
  }
};