问题
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