Laravel echo: channel authorization

泪湿孤枕 提交于 2020-05-24 07:09:53

问题


From the Broadcasting documentation

Broadcast::channel('order.{orderId}', function ($user, $orderId) {
    return $user->id === Order::findOrNew($orderId)->user_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.

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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/61629898/laravel-echo-channel-authorization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!