Laravel /broadcasting/auth Always Fails With 403 Error

后端 未结 8 2143
时光取名叫无心
时光取名叫无心 2021-01-04 03:58

I have recently delved into Laravel 5.3\'s Laravel-Echo and Pusher combination. I have successfully set up public channels and moved on to private ones. I am having trouble

8条回答
  •  情书的邮戳
    2021-01-04 04:15

    Error 403 /broadcasting/auth with Laravel version > 5.3 & Pusher, you need change your code in resources/assets/js/bootstrap.js with

    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: 'your key',
        cluster: 'your cluster',
        encrypted: true,
        auth: {
            headers: {
                Authorization: 'Bearer ' + YourTokenLogin
            },
        },
    });
    

    And in app/Providers/BroadcastServiceProvider.php change by

    Broadcast::routes()
    

    with

    Broadcast::routes(['middleware' => ['auth:api']]);
    

    or

    Broadcast::routes(['middleware' => ['jwt.auth']]); //if you use JWT
    

    it worked for me, and hope it help you.

提交回复
热议问题