我正试图让我的应用程序连接到一个私人频道上的推手。
但是,我在控制台中得到了以下错误:
发布http://localhost:8000/broadcasting/auth 403 (禁止)
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);
});错误的原因可能是什么,以及如何解决。
发布于 2018-05-18 07:26:13
错误403 /广播/auth与Laravel版本> 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它对我有用,希望它能帮助你。
发布于 2022-02-23 05:55:26
你有没有试过定制你的authEndpoint。
这东西在我这边管用。
bootsrap.js
window.Echo = new Echo({
broadcaster: 'pusher',
// ...
authEndpoint: '/custom/endpoint/auth'
});发布于 2018-04-26 00:27:50
在我的例子中,我使用了一个造成问题的自定义警卫。
我添加了中间件来通过我的自定义安全机制,这解决了这个问题。
public function boot()
{
Broadcast::routes(['middleware' => 'auth:admin']);
require base_path('routes/channels.php');
}这链接更详细地解释了发生了什么。
https://stackoverflow.com/questions/47643417
复制相似问题