【问题标题】:Laravel pusher, /broadcasting/auth:1 Failed to load resource: the server responded with a status of 500 (Internal Server Error)Laravel pusher,/broadcasting/auth:1 加载资源失败:服务器响应状态为 500(内部服务器错误)
【发布时间】:2020-11-30 05:22:08
【问题描述】:

我清除 cookie,然后登录帐户并获取令牌,一旦我进入任何有套接字的页面,我就会收到错误:

[2020-08-10 17:50:43] local.ERROR:资源所有者或授权 服务器拒绝了请求。 {“异常”:“[对象] (League\OAuth2\Server\Exception\OAuthServerException(代码:9): 资源所有者或授权服务器拒绝了该请求。在 C:\laragon\www\delivery\vendor\league\oauth2-server\src\Exception\OAuthServerException.php:243) [堆栈跟踪] #0 C:\laragon\www\delivery\vendor\league\oauth2-server\src\AuthorizationValidators\BearerTokenValidator.php(88): League\OAuth2\Server\Exception\OAuthServerException::accessDenied('The JWT 字符串 ...', NULL, Object(InvalidArgumentException))

[previous exception] [object] (InvalidArgumentException(code: 0): The JWT 字符串必须有两个点

local.ERROR: Route [login] 未定义。 {“异常”:“[对象] (Symfony\Component\Routing\Exception\RouteNotFoundException(代码: 0): 路由[登录] 未定义。在 C:\laragon\www\delivery\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php:420) [堆栈跟踪]

如果我重新加载页面,错误就会永远消失。这些错误仅在您第一次进入使用套接字的页面时出现,我在前端使用 vue js。对于身份验证,我使用的是 laravel 护照。

我的推杆的本地设置

indow.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    authEndpoint: '/broadcasting/auth',
    auth:{
        headers:{
            Authorization:'Bearer ' + Cookies.get('access_token'),
        },
    },
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    encrypted:false,
    forceTLS: false,
    enabledTransports: ['ws', 'wss'],
});

生产有安全连接,存在错误。

我使用 laravel 护照进行身份验证

【问题讨论】:

  • 您是否检查过发送到您服务器的请求?授权标头是否正确发送到服务器?
  • 是的,我通过将推送器的初始化添加到已安装组件的挂钩来解决此问题,在此之前我的推送器在任何页面上都被初始化,无论用户是否登录,因为当去到登录页面,推送器被初始化为一个未定义的令牌,因为用户没有登录系统。

标签: laravel pusher


【解决方案1】:

错误信息为:Route [login] not defined

...这意味着您缺少默认的Auth::routes()

运行 php artisan ui vue --auth 以获取新应用。

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 1970-01-01
    • 2018-01-22
    • 2014-11-24
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多