当前位置: 首页 > 知识库问答 >
问题:

Laravel Echo“无法对客户端进行身份验证,已获取HTTP状态405”

汤承允
2023-03-14

我能够使用HTTPS设置在本地环境上运行laravel echo服务器。但是,我的生产服务器(基于Forge)似乎存在一个问题:

Client cannot be authenticated, got HTTP status 405

我能够通过HTTPS在本地测试私有通道,它工作得很好,所以看起来不存在配置问题。

我应该提到的是,我使用的是LaravelPassport,导致此错误的请求被抛出到常规身份验证中间件之外的页面上。

为了确保它不是我的身份验证方法,我让它在我的通道配置中返回“true”:

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

Broadcast::channel('channelReceiveLiveData.{id}', function ($user, $id) {
    return true;
});

Broadcast::channel('channelReceiveTestState.{id}', function ($id) {
    return true;
});

以下是监听专用频道的my echo listener版本:

Echo.private('channelReceiveLiveData.' + this.$route.params.testID)
.listen('liveDataTrigger', (e) => {
    if (!that.state.hasPulledInitialData) {
        console.log('Receiving data before initial pull done');
    }

我的laravel echo服务器。json文件:

 "authHost": "https://app.test.com",
 "authEndpoint": "/broadcasting/auth",
 "clients": [
            {
                    "appId": "....",
                    "key": "...."
            }
    ],
    "database": "redis",
    "databaseConfig": {
            "redis": {},
            "sqlite": {
                    "databasePath": "/database/laravel-echo-server.sqlite"
            }
    },
    "devMode": false,
    "host": null,
    "port": "6001",
    "protocol": "https",
    "socketio": {},
    "sslCertPath": "/etc/nginx/ssl/app.test.com/ssl/server.crt",
    "sslKeyPath": "/etc/nginx/ssl/app.test.com/ssl/server.key",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "apiOriginAllow": {
            "allowCors": false,
            "allowOrigin": "",
            "allowMethods": "",
            "allowHeaders": ""
    }
}

下面是laravel-echo-server的详细输出:

Client can not be authenticated, got HTTP status 405
  socket.io-parser encoding packet {"type":2,"data":["subscription_error","private-channelReceiveTestState.asdf23f",405],"nsp":"/"} +234ms
  socket.io-parser encoded {"type":2,"data":["subscription_error","private-channelReceiveTestState.asdf23f",405],"nsp":"/"} as 2["subscription_error","private-channelReceiveTestState.asdf23f",405] +1ms
  socket.io:client writing packet ["2[\"subscription_error\",\"private-channelReceiveTestState.asdf23f\",405]"] +356ms
  engine:socket sending packet "message" (2["subscription_error","private-channelReceiveTestState.asdf23f",405]) +237ms
  engine:socket flushing buffer to transport +0ms
  engine:polling writing "70:42["subscription_error","private-channelReceiveTestState.asdf23f",405]" +187ms
  engine upgrading existing transport +221ms
  engine:socket might upgrade socket transport from "polling" to "websocket" +36ms
  engine intercepting request for path "/socket.io/" +25ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MGQq611&sid=6gfNSDGZdH3lXQwZAAAA" +0ms
  engine setting new request for existing client +1ms
  engine:polling setting request +60ms
  engine:socket executing batch send callback +25ms
  engine:ws received "2probe" +0ms
  engine:ws writing "3probe" +1ms
  engine:socket writing a noop packet to polling for fast upgrade +129ms
  engine:polling writing "1:6" +129ms
  engine:ws received "5" +152ms
  engine:socket got upgrade packet - upgrading +50ms
  engine:polling closing +51ms
  engine:polling transport discarded - closing right away +0ms
  engine intercepting request for path "/socket.io/" +838ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MGQq6E8" +1ms
  engine handshaking client "_glN99nDAdsKhhZBAAAB" +2ms
  engine:socket sending packet "open" ({"sid":"_glN99nDAdsKhhZBAAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}) +663ms
  engine:socket sending packet "message" (0) +3ms
  engine:polling setting request +666ms
  engine:socket flushing buffer to transport +1ms
  engine:polling writing "96:0{"sid":"_glN99nDAdsKhhZBAAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40" +0ms
  engine:socket executing batch send callback +1ms
  socket.io:server incoming connection with id _glN99nDAdsKhhZBAAAB +1s
  socket.io:client connecting to namespace / +910ms
  socket.io:namespace adding socket to nsp / +1s
  socket.io:socket socket connected - writing packet +1s
  socket.io:socket joining room _glN99nDAdsKhhZBAAAB +0ms
  socket.io:socket packet already sent in initial handshake +1ms
  socket.io:socket joined room _glN99nDAdsKhhZBAAAB +0ms
  engine intercepting request for path "/socket.io/" +65ms
  engine handling "POST" http request "/socket.io/?EIO=3&transport=polling&t=MGQq6FB&sid=_glN99nDAdsKhhZBAAAB" +1ms
  engine setting new request for existing client +0ms
  engine:polling received "133:42["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]" +62ms
  engine:socket packet +62ms
  socket.io-parser decoded 2["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] as {"type":2,"nsp":"/","data":["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]} +971ms
  socket.io:socket got packet {"type":2,"nsp":"/","data":["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]} +59ms
  socket.io:socket emitting event ["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] +0ms
  socket.io:socket dispatching an event ["subscribe",{"channel":"channelReceiveLiveData.3","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] +1ms
  socket.io:socket joining room channelReceiveLiveData.3 +0ms
  socket.io:socket joined room channelReceiveLiveData.3 +0ms
  engine intercepting request for path "/socket.io/" +5ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MGQq6FD&sid=_glN99nDAdsKhhZBAAAB" +0ms
  engine setting new request for existing client +0ms
  engine:polling setting request +5ms
  engine upgrading existing transport +118ms
  engine:socket might upgrade socket transport from "polling" to "websocket" +122ms
  engine:ws received "2probe" +900ms
  engine:ws writing "3probe" +1ms
  engine:socket writing a noop packet to polling for fast upgrade +149ms
  engine:polling writing "1:6" +268ms
  engine:ws received "5" +150ms
  engine:socket got upgrade packet - upgrading +50ms
  engine:polling closing +49ms
  engine:polling transport discarded - closing right away +1ms
  socket.io:client client close with reason transport close +10s
  socket.io:socket closing socket - reason transport close +10s
  engine intercepting request for path "/socket.io/" +10s
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MGQq8qd" +1ms
  engine handshaking client "rbDPCyhJNywypMPLAAAC" +0ms
  engine:socket sending packet "open" ({"sid":"rbDPCyhJNywypMPLAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}) +10s
  engine:socket sending packet "message" (0) +0ms
  engine:polling setting request +10s
  engine:socket flushing buffer to transport +1ms
  engine:polling writing "96:0{"sid":"rbDPCyhJNywypMPLAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}2:40" +1ms
  engine:socket executing batch send callback +0ms
  socket.io:server incoming connection with id rbDPCyhJNywypMPLAAAC +11s
  socket.io:client connecting to namespace / +584ms
  socket.io:namespace adding socket to nsp / +11s
  socket.io:socket socket connected - writing packet +585ms
  socket.io:socket joining room rbDPCyhJNywypMPLAAAC +0ms
  socket.io:socket packet already sent in initial handshake +1ms
  socket.io:socket joined room rbDPCyhJNywypMPLAAAC +0ms
  engine intercepting request for path "/socket.io/" +96ms
  engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=MGQq8s8&sid=rbDPCyhJNywypMPLAAAC" +0ms
  engine setting new request for existing client +7ms
  engine:polling setting request +101ms
  engine intercepting request for path "/socket.io/" +19ms
  engine handling "POST" http request "/socket.io/?EIO=3&transport=polling&t=MGQq8sY&sid=rbDPCyhJNywypMPLAAAC" +0ms
  engine setting new request for existing client +0ms
  engine:polling received "148:42["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]" +20ms
  engine:socket packet +121ms
  socket.io-parser decoded 2["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] as {"type":2,"nsp":"/","data":["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]} +11s
  socket.io:socket got packet {"type":2,"nsp":"/","data":["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}]} +118ms
  socket.io:socket emitting event ["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] +1ms
  socket.io:socket dispatching an event ["subscribe",{"channel":"private-channelReceiveTestState.asdf23f","auth":{"headers":{"X-CSRF-TOKEN":"6qYUDXsZb7dKnqjOfOdmucoCw9bHi5OiqMIVQoRt"}}}] +0ms

共有1个答案

百里丁雨
2023-03-14

我也有同样的问题。我在laravel echo服务器中更新了authEndpoint变量。json配置文件。

"AuthEndpoint":"/api/广播/auth",

当我在项目中列出路线时,我看到了这一行。

|        | GET|POST|HEAD | api/broadcasting/auth                   |                       | Illuminate\Broadcasting\BroadcastController@authenticate                  | auth:api                                             |

它验证了它。

使用Laravel Framework 7.18进行更新。0

|        | GET|POST|HEAD | broadcasting/auth                       |                                   | Illuminate\Broadcasting\BroadcastController@authenticate                  | web        |

P. S.我使用Laravel护照与Laravel回声服务器

 类似资料:
  • 我正在建一个水疗中心。我使用laravel作为后端,vuejs作为前端。它们在不同的端口上独立运行。(使用laravel api) Laravel在8000上运行 Vue在8082上运行 我允许用户使用JWT Auth进行身份验证。 我正在尝试使用laravel echo服务器制作一个实时数据传输应用程序,并使用公共通道传输数据,效果非常好。 现在,我需要使用私有通道将数据广播给经过身份验证的用户

  • 我已经安装了Laravel回声服务器和Laravel回声客户端。 以下是laravel echo服务器。json配置。 以下脚本侦听通道事件。它可以通过很好地构建。 尝试侦听命令上的任何事件时。它不断抛出。 注: 我在laravel echo服务和谷歌上都没有发现任何有用的东西。 任何帮助将不胜感激。 拉威尔V5。4. 谢谢

  • 我不熟悉SSL和证书。我一直在做关于客户端证书认证的研究。我看过这个和wiki。 因此,如果我必须为我的B2B REST服务实现客户端证书身份验证解决方案,我应该执行以下操作 要求客户端生成自己的私钥,并为其公钥生成证书(CA 颁发?)。通过电子邮件或 USB 闪存盘发送该证书。 在服务器端将客户端的公共证书导入信任存储区并启用客户端身份验证 在握手期间,客户端会出示其证书并进行身份验证,因为服务

  • 授权服务器为进行客户端身份验证的目的,为Web应用客户端创建客户端凭据。授权服务器被鼓励考虑比客户端密码更强的客户端身份验证手段。Web应用程序客户端必须确保客户端密码和其他客户端凭据的机密性。 授权不得向本地应用程序或基于用户代理的应用客户端颁发客户端密码或其他客户端凭据用于客户端验证目的。授权服务器可以颁发客户端密码或其他凭据给专门的设备上特定安装的本地应用程序客户端。 当客户端身份验证不可用

  • 在向令牌端点发起请求时,机密客户端或其他被颁发客户端凭据的客户端必须如2.3节所述与授权服务器进行身份验证。客户端身份验证用于: 实施刷新令牌和授权码到它们被颁发给的客户端的绑定。当授权码在不安全通道上向重定向端点传输时,或者 当重定向URI没有被完全注册时,客户端身份验证是关键的。 通过禁用客户端或者改变其凭据从被入侵的客户端恢复,从而防止攻击者滥用被盗的刷新令牌。改变单套客户端凭据显然快于撤销