php – Laravel广播认证路由只返回“true”
我有我的推杆键设置并在Laravel 5.3中初始化.当我在我的本地环境中测试时,它可以工作.当我尝试在生产环境中运行完全相同的代码时,我收到此错误:
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth info required to subscribe to private-App.User.16"}}} 我已经确认Pusher键在我的本地和制作上是相同的. WS在两个环境中初始化相同: wss://ws.pusherapp.com/app/264P9d412196d622od64d?protocol=7&client=js&version=4.1.0&flash=false 我能看到的唯一区别是,当我们的生产服务器联系Laravel“broadcast / auth”路由时,它只在响应正文中收到true. 当我的本地联系人“广播/认证”时,它会在响应中得到: {auth: "22459d41299d6228d64d:df5d393fe37df0k3832fa5556098307f145d7e483c07974d8e7b2609200483f8"} 在我的BroadcastServiceProvider.php中: public function boot() { Broadcast::routes(); // Authenticate the user's personal channel. Broadcast::channel('App.User.*',function (User $user,$user_id) { return (int)$user->id === (int)$user_id; }); } 什么可能导致广播/验证路由返回简单而不是预期的身份验证?
如果您检查PusherBroadcaster.php文件,您将看到响应可以“混合”.
我认为文档只是说默认广播.
这是PusherBroadcast中的validAuthenticationResponse方法. /** * Return the valid authentication response. * * @param IlluminateHttpRequest $request * @param mixed $result * @return mixed */ public function validAuthenticationResponse($request,$result) { if (Str::startsWith($request->channel_name,'private')) { return $this->decodePusherResponse( $this->pusher->socket_auth($request->channel_name,$request->socket_id) ); } return $this->decodePusherResponse( $this->pusher->presence_auth( $request->channel_name,$request->socket_id,$request->user()->getAuthIdentifier(),$result) ); } 只是给你另一个例子,这是在RedisBroadcast里面. if (is_bool($result)) { return json_encode($result); } 关于这个“身份验证请求”的简短说明: BroadcastManager实例化所有“可用驱动程序”(Pusher,Redis,Log等),并创建“auth”路由(使用BroadcastController身份验证方法). 当您调用“auth”时,会发生这种情况: >调用“broadc … / auth”路由. 简短回答: Soo .. Pusher需要这个身份验证响应.否则,您将无法连接/识别用户(wss://ws.pusherapp.com ….). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |