【问题标题】:500 Authenticating on Laravel Echo Server Class App\\Http\\Middleware\\Authenticate:api does not exist500 Authenticating on Laravel Echo Server Class App\\Http\\Middleware\\Authenticate:api 不存在
【发布时间】:2021-03-17 17:14:57
【问题描述】:

我在使用 Laravel Echo Server 的私人频道时遇到错误。

laravel-echo-server.json

{
        "authHost": "https://testapi.test.com",
        "authEndpoint": "/api/broadcasting/auth",
        "clients": [],
        "database": "redis",
        "databaseConfig": {
                "redis": {},
                "sqlite": {
                        "databasePath": "/database/laravel-echo-server.sqlite"
                }
        },
        "devMode": true,
        "host": null,
        "port": "6001",
        "protocol": "https",
        "socketio": {},
        "secureOptions": 67108864,
        "sslCertPath": "/etc/nginx/ssl/server.crt",
        "sslKeyPath": "/etc/nginx/ssl/server.key",
        "sslCertChainPath": "",
        "sslPassphrase": "",
        "subscribers": {
                "http": true,
                "redis": true
        },
        "apiOriginAllow": {
                "allowCors": true,
                "allowOrigin": "*",
                "allowMethods": "GET, POST",
                "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
        }
}

环境:

LARAVEL_ECHO_SERVER_AUTH_HOST=http://test.test
LARAVEL_ECHO_SERVER_SSL_CERT=""
LARAVEL_ECHO_SERVER_SSL_KEY=""
LARAVEL_ECHO_SERVER_PROTO=http

Chrome 显示:

42["subscription_error", "private-user.5971", 500]
0: "subscription_error"
1: "private-user.5971"
2: 500

日志显示

 [1:56:03 AM] - f4rbj7htL2hrRqQRAAAA could not be authenticated to private-user.5971
{
    "message": "Class App\\Http\\Middleware\\Authenticate:api does not exist",
    "exception": "ReflectionException",
    "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
    "line": 718,
    "trace": [
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 718,
            "function": "__construct",
            "class": "ReflectionClass",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php",
            "line": 731,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "function": "Illuminate\\Support\\Traits\\{closure}",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Collections/Arr.php",
            "line": 664,
            "function": "array_filter"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Collections/Collection.php",
            "line": 344,
            "function": "where",
            "class": "Illuminate\\Support\\Arr",
            "type": "::"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php",
            "line": 733,
            "function": "filter",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 723,
            "function": "reject",
            "class": "Illuminate\\Support\\Collection",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 685,
            "function": "gatherRouteMiddleware",,
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 669,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 635,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 624,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 166,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 128,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php",
            "line": 67,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
            "line": 87,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/app/Http/Middleware/Cors.php",
            "line": 28,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 167,
            "function": "handle",
            "class": "App\\Http\\Middleware\\Cors",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 103,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 141,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/home/vagrant/myproject/public/index.php",
            "line": 52,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}
Client can not be authenticated, got HTTP status 500

我不明白为什么私人频道不起作用。公开的虽然可以。任何帮助都会很棒!我最近确实从 5.7 升级到了 Laravel 8,但后来查看了另一个在 8 中没有任何问题的项目。

谢谢!

配置/auth.php:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
            'hash' => false,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
            'throttle' => 60,
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Password Confirmation Timeout
    |--------------------------------------------------------------------------
    |
    | Here you may define the amount of seconds before a password confirmation
    | times out and the user is prompted to re-enter their password via the
    | confirmation screen. By default, the timeout lasts for three hours.
    |
    */

    'password_timeout' => 10800,

];

【问题讨论】:

  • 错误意味着它无法用api 保护解析App\\Http\\Middleware\\Authenticate。是否在config/auth.php 中配置了 api guard 验证
  • @Donkarnash 我设置了 api 保护...检查更新的问题

标签: laravel socket.io laravel-echo


【解决方案1】:

我必须在 laravel-echo-server.json 文件中更改这一行

"authEndpoint": "/api/broadcasting/auth",

"authEndpoint": "/broadcasting/auth",

【讨论】:

    猜你喜欢
    • 2021-03-18
    • 1970-01-01
    • 2018-11-10
    • 2017-12-04
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2018-08-19
    • 2020-05-05
    相关资源
    最近更新 更多