Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel Echo private channel: /broadcasting/auth returns 403

ErrorPOST /broadcasting/auth 403 (Forbidden)

Short answer

A 403 from /broadcasting/auth means Laravel refused the subscription. Either the request has no authenticated user for the guard in use, so the callback never runs, or the callback in routes/channels.php returned false for that channel. List the channels, then test the callback with the logged-in user.

  • Applies to Laravel 12, PHP 8.3, Laravel Echo
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List the channel callbacks Laravel has registered and compare them to the channel name your frontend subscribes to.

    php artisan channel:list
  2. 2Match what you see, then jump to its fix

    1. 1403 only for guests, or when the page uses a different guard than webThe request is not authenticated for the guard that authorizes channelsFix
    2. 2Signed-in user still gets 403 for one specific channelThe authorization callback returns falseFix

What does the error look like?

  • POST /broadcasting/auth 403 (Forbidden)

Cause 1 of 2

The request is not authenticated for the guard that authorizes channels

1Check

Private and presence channels authenticate with the default guard. If the user is not authenticated, authorization is denied and the callback is never executed.

php artisan tinker   # then run: config('auth.defaults.guard')

2Fix

Make sure the user is signed in with that guard when Echo connects, or name the guards the channel accepts.

Broadcast::channel('orders.{orderId}', function ($user, int $orderId) {
    return $user->id === Order::findOrNew($orderId)->user_id;
}, ['guards' => ['web', 'admin']]);

3Verify

Reload the page while signed in and watch the auth request return 200.

php artisan channel:list

Confirmed by laravel.com

Did this fix it?

Cause 2 of 2

The authorization callback returns false

1Check

The callback must return true or false. A strict comparison between an integer and a string id, or a wrong owner column, returns false.

php artisan tinker
>>> $u = App\Models\User::first(); $o = App\Models\Order::first();
>>> $u->id === $o->user_id

2Fix

Fix the comparison or the lookup in routes/channels.php so it returns true for the owner.

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

3Verify

Subscribe as the owner and as another user: the owner connects, the other gets 403.

php artisan channel:list

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Keep channel names in routes/channels.php and the frontend in step; list them with channel:list after every change.
  • Add a feature test for each private channel with an owner and a stranger.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.