【发布时间】:2015-09-30 10:00:26
【问题描述】:
我正在研究 websockets,我正在使用Rachet。每当用户尝试建立连接时,我都需要进行身份验证。我的后端使用 laravel 5 进行所有 http 身份验证。
我的服务器代码是这样的:
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
我尝试使用 laravel
Auth::user()
我收到以下错误:
在 null 时调用成员函数 user()
每当我尝试从浏览器连接到 websockets 时,它都会使用 ws protcol 和 rachets 服务器,因此永远不会调用 laravel 路由。这是我尝试使用Auth::user() 时出错的原因吗?
我可以使用该 cookie 来验证用户是否已登录?还有其他解决方案吗?会涉及哪些安全风险?
【问题讨论】:
标签: php laravel cookies laravel-5 session-variables