I've spent a couple of days on this now and can not get my head around it. I'm using this Laravel Package Ohmybrew/Laravel-Shopify which does not use the standard Laravel auth as they have their own middleware auth.shop
The issue I am facing is because it does not use the $user variable as the default Auth is not there, broadcast authentication for WebSockets on private channels is always 403 not authorised.
I've tried returning true usings another model, does not work.
Broadcast::channel('shop.{id}', function ($user, $id) {
$shop = ShopifyApp::shop();
return (int) $shop->id === (int) $id;
});
I've also tried just returning true no matter what just to see. Also no luck.
Broadcast::channel('shop.{id}', function ($user, $id) {
return true
});
I've even messed about with the PusherBroadcast.php and BroadcastManager to remove throwing the not authenticated exception. This also does not work.
I'm still getting to grips with the way Laravel works as a whole package so not sure where to look next. I've had a read up on custom auth guards but not sure that will work as the package has its own authentication.
Any steer would be greatly appreciated as I am a little out of things to try. It seems anything I do to get onto a private channel does not work.
Note: It's worth mentioning a test public channel for listening to the WebSockets works fine with the current set up. it is only the private channel authentication which is not working.
Update: Here is how I am listening to the channels
window.Echo.private('shop.{{ ShopifyApp::shop()->id }}')
.listen('ScheduleProcessed', function(e) {
console.log(e);
});
window.Echo.channel(`test`) // Broadcast channel name
.listen('BroadcastTestEvent', (e) => { // Message name
console.log(e); // The operation performed by the message, the parameter e is the data carried
alert("GOT S**T");
}
);
The second one for the test channel works completely fine. The 'shop' channel does not and it's partly down to broadcasting/auth always returns 403 when the client tries to connect to the private channel.
Update 2
Seems to have something to do with the fact the default auth needs to use the $request->user() which is empty as the custom auth does not use it at all.
I've read that binding the user might work but not 100% sure how.
$request->merge(['user' => $user]);
//add this
$request->setUserResolver(function () use ($user) {
return $user;
});

broadcasting/authnever connects as it returns 403 - Kyon147