mercredi 30 septembre 2015

How to authenticate user manually from cookie in laravel 5?

I am working on websockets, i am using Rachet. Whenever a user tries to establish a connection, i need to authenticate. My backend uses laravel 5 for all http authentification.

My server code is like this :

    public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
       if (null === $request) {
            throw new \UnexpectedValueException('$request can not be null');
       }
       $cookie = $request->getCookie('laravel_session'); 
//do authentification with cookie if possible

I tried to use laravel

Auth::user()

I got following error :

Call to member function user() on null

Whenever i try to connect to websockets from browser, it will use ws protcol and rachets server, so laravel routes are never getting called. Is that the reason i am getting an error when i try to use Auth::user() ?

Can i use that cookie to verify if user is logged in? Is there any other solutions? What will be the security risks involved?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1WxmVz8
via IFTTT

Aucun commentaire:

Enregistrer un commentaire