tlaverdure / laravel-echo-server

Socket.io server for Laravel Echo
MIT License
2.64k stars 509 forks source link

Authenticate users before websocket connection establishes #558

Open HASSANDL opened 3 years ago

HASSANDL commented 3 years ago

How only allow authenticated users to establish a successful websocket connection? in client side use laravel-echo

{
  "authHost": "http://localhost",
  "authEndpoint": "/broadcasting/auth",
  "clients": [
    {
      "appId": "620bafdba22974a2",
      "key": "e860c5fc92f4a20e7175754eb030e737"
    }
  ],
  "database": "redis",
  "databaseConfig": {
    "redis": {
      "host": "localhost",
      "port": 6379
    },
    "sqlite": {
      "databasePath": "/database/laravel-echo-server.sqlite"
    }
  },
  "devMode": true,
  "host": null,
  "port": 7000,
  "protocol": "http",
  "socketio": {
    "pingTimeout": 5000,
    "pingInterval": 2000000
  },
  "secureOptions": 67108864,
  "sslCertPath": "",
  "sslKeyPath": "",
  "sslCertChainPath": "",
  "sslPassphrase": "",
  "subscribers": {
    "http": false,
    "redis": true
  },
  "apiOriginAllow": {
    "allowCors": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
  }
}
iooe commented 3 years ago

<meta name="user" content="{{Auth::user()}}"> `

    const user = document.querySelector('meta[name="user"]').getAttribute('content')

    if (user !== null) {

        this.echoInstance = new Echo({
          ...
        });

    }`
N3XT0R commented 3 years ago

https://laravel.com/docs/8.x/broadcasting#concept-overview