Laravel棘轮插槽Auth
问题描述:
我开始学习棘轮(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连接。
答
好玩弄找到解决方案,它似乎确定: 我使用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);
如果有更好的解决方案,请发表评论
答
无法使用验证::用户()与WebSocket一起。 WebSocket服务器正在处理多个连接(所以Auth :: user()剂量有任何意义)。但是你可以访问用户会话。
更多的细节在这里
https://laravel.io/forum/01-16-2015-loading-laravels-session-using-ratchet