2016-01-13 116 views
1

我开始学习棘轮(reactPHP)我正在使用laravel。但是我对安全问题有所了解。 我怎么能拒绝基于在用户登录或不Laravel棘轮插槽Auth

public function onOpen(ConnectionInterface $conn) 
    { 
     $this->clients->attach($conn); 
     $this->users[$conn->resourceId] = $conn; 
     if(Auth::check()){ 
      echo 'user logged in'; 
     }else{ 
      echo "New connection! ({$conn->resourceId})\n"; 
     } 

    } 

我用这样的事情,但它通过验证::检查和控制台总是显示新建连接WebSocket连接。

回答

0

好玩弄找到解决方案,它似乎确定: 我使用Sentinel

$session = (new SessionManager(App::getInstance()))->driver(); 
$cookies = $conn->WebSocket->request->getCookies(); 
$laravelCookie = urldecode($cookies['timeline_auth']); 
$idSession = Crypt::decrypt($laravelCookie); 
$user = Sentinel::findByPersistenceCode($idSession); 

如果有更好的解决方案,请发表评论