【问题标题】:POST http://localhost:8000/broadcasting/auth 403 (Forbidden)POST http://localhost:8000/broadcasting/auth 403(禁止)
【发布时间】:2018-05-18 12:17:15
【问题描述】:

我正在尝试让我的应用连接到私人频道上的推送器。

但我在控制台中收到以下错误:

POST http://localhost:8000/broadcasting/auth403(禁止)

app.js

 /**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('payment', require('./components/Payment.vue'));
Vue.component('form-ajax', require('./components/FormAjax.vue'));
Vue.component(
    'passport-clients',
    require('./components/passport/Clients.vue')
);

Vue.component(
    'passport-authorized-clients',
    require('./components/passport/AuthorizedClients.vue')
);

    Vue.component(
    'passport-personal-access-tokens',
    require('./components/passport/PersonalAccessTokens.vue')
);

const app = new Vue({
    el: '#app'
});

Echo.private(`articles.admin`)
    .listen('ArticleEvent', function(e)  {
        console.log(e);
    });

Error

错误的原因可能是什么以及如何解决它。

【问题讨论】:

    标签: laravel


    【解决方案1】:

    Error 403 /broadcasting/auth with Laravel version > 5.3 & Pusher,你需要在 resources/assets/js/bootstrap.js 中更改代码

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

    并且在 app/Providers/BroadcastServiceProvider.php 中更改为

    Broadcast::routes()
    

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

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

    它对我有用,希望对你有所帮助。

    【讨论】:

    • 我们如何使用自定义身份验证 BroadcastServiceProvider.php @Alex
    • @Alex 什么是“YourTokenLogin”,我该如何暗示呢?
    【解决方案2】:

    在我的情况下,我使用了导致问题的自定义身份验证保护。

    我添加了中间件来传递我的自定义身份验证保护,这解决了问题。

    public function boot()
    {
        Broadcast::routes(['middleware' => 'auth:admin']);
    
        require base_path('routes/channels.php');
    }
    

    This 链接解释了更多正在发生的事情。

    【讨论】:

      【解决方案3】:

      我将下面的代码添加到routes/web.php 并且成功了。

       Route::post('/broadcasting/auth', function () {
          return Auth::user();
       });
      

      【讨论】:

        【解决方案4】:

        您是否尝试过自定义您的 authEndpoint。

        这件事对我有用。

        bootsrap.js

        window.Echo = new Echo({
            broadcaster: 'pusher',
            // ...
            authEndpoint: '/custom/endpoint/auth'
        });
        

        【讨论】:

          猜你喜欢
          • 2017-06-01
          • 1970-01-01
          • 2019-12-31
          • 2020-07-23
          • 2021-04-08
          • 2016-05-03
          • 1970-01-01
          • 1970-01-01
          • 2019-11-21
          相关资源
          最近更新 更多