Laravel回声:频道授权 [英] Laravel echo: channel authorization

查看:55
本文介绍了Laravel回声:频道授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自广播文档

Broadcast::channel('order.{orderId}', function ($user, $orderId) {
    return $user->id === Order::findOrNew($orderId)->user_id;
});

所有授权回调将当前经过身份验证的用户作为其第一个参数,并将任何其他通配符参数作为其后继参数.在此示例中,我们使用 {orderId} 占位符指示频道名称的"ID"部分为通配符.

All authorization callbacks receive the currently authenticated user as their first argument and any additional wildcard parameters as their subsequent arguments. In this example, we are using the {orderId} placeholder to indicate that the "ID" portion of the channel name is a wildcard.

句子所有授权回调均将当前经过身份验证的用户作为其第一个参数对于在网络上广播是正确的,如果我们为移动应用程序构建广播并且来自移动应用程序的用户想要订阅该怎么办频道?然后,此 user 将不再存在.

The sentence All authorization callbacks receive the currently authenticated user as their first argument is true for broadcasting on web, what if we build broadcasting for mobile application and a user from a mobile application wants to subscribe to a channel? Then this user wont exist any more.

我们如何授权来自移动应用程序的用户?

How can we authorize users coming from mobile application?

推荐答案

找到了它.服务器和客户端中使用的协议必须相同.尽管Laravel Echo使用Socket.io,但在android应用程序上安装Socket.io不会起作用.我必须在android上安装 LaravelEchoAndroid 程序包,并使用Bearer令牌作为身份验证.

Found it. The protocol used in server and client must be the same. Despite of the fact Laravel Echo uses Socket.io, but installing Socket.io on android application wont work. I have to install LaravelEchoAndroid package on android and use Bearer token as authentication.

提示:该软件包有一个编译错误,通过更改maven可以使用.

Hint: This package has a compile error and by changing maven it will work.

这篇关于Laravel回声:频道授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆