php - How to authenticate user manually from cookie in laravel 5? -
i working on websockets, using rachet. whenever user tries establish connection, need authenticate. backend uses laravel 5 http authentification.
my server code :
public function onopen(connectioninterface $conn, requestinterface $request = null) { if (null === $request) { throw new \unexpectedvalueexception('$request can not null'); } $cookie = $request->getcookie('laravel_session'); //do authentification cookie if possible
i tried use laravel
auth::user()
i got following error :
call member function user() on null
whenever try connect websockets browser, use ws protcol , rachets server, laravel routes never getting called. reason getting error when try use auth::user()
?
can use cookie verify if user logged in? there other solutions? security risks involved?
i got myself.
require_once getcwd() . '/bootstrap/autoload.php'; $app = require getcwd() . '/bootstrap/app.php'; $kernel = $app->make(\illuminate\contracts\http\kernel::class); // var_dump('kernel booted successfully'); $response = $kernel->handle( $request = \illuminate\http\request::capture() ); // var_dump('response object created'); // var_dump('decrypting cookie : '); // var_dump($cookie); $id = $app['encrypter']->decrypt($cookie); // var_dump('id decrypted : '.$id); $app['session']->driver()->setid($id); $app['session']->driver()->start(); $user = $app['auth']->check(); //if not logged in if( $user == false ){ return false; }else{ //return instance of app return $app; //to user details: $app['auth']->user() }
Comments
Post a Comment