最近,我在laravel服务器中遇到了一个身份验证错误。
我成功地建立了一个使用Laravel + Vue.js的应用程序,以及由auth:api 中间件保护的端点,运行良好。
但是,当我尝试使用Laravel对用户进行身份验证时,我在laravel-echo-server.日志中得到了405个异常
为了向laravel-echo-server的api端点添加身份验证,我将api的内容更改为
下面是我的laravel-echo-server.json文件的样子
{
"authHost": "http://192.168.225.128",
"authEndpoint": "/api/broadcasting/auth",
"clients": [
{
"appId": "APP_ID",
"key": "APP_KEY"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "3389",
"protocol": "http",
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"apiOriginAllow": {
"allowCors": true,
"allowOrigin": "http://192.168.225.128",
"allowMethods": "OPTIONS, GET, POST",
"allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}
}这就是在Vue.js应用程序中配置回送服务器的方式:
import Vue from 'vue';
import Echo from 'laravel-echo';
const io = require('socket.io-client');
import store from '~/store';
window.io = io;
if (typeof io !== undefined) {
let authenticationToken = store.getters['account/token'];
let authenticated = store.getters['account/authenticated'];
let echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':3389',
auth: {
headers: {
Authorization: (authenticated) ? 'Bearer ' + authenticationToken : ''
}
}
});
window.Echo = echo;
if (! Vue.hasOwnProperty('$echo')) {
Object.defineProperty(Vue.prototype, '$echo', {
get() {
return echo;
}
});
}
if (! Vue.hasOwnProperty('$io')) {
Object.defineProperty(Vue.prototype, '$io', {
get() {
return io;
}
});
}
}考虑到laravel-echo-server发出405错误,这意味着传递给订阅服务的所有数据都是正确的,但是,出于某种原因,我在laravel-echo-server错误日志中得到了不允许的方法。
为了澄清,我附上日志本身。
发布于 2019-01-10 15:23:23
我猜广播线路没有连接起来。
您需要在config/app.php中取消注释App\Providers\BroadcastServiceProvider::class。
您可以在运行php artisan route:list时确认,api/ can /auth应该出现在那里。
https://stackoverflow.com/questions/52386826
复制相似问题