From dd369adb1738860a94471269f3c02f3444e3ef0c Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Mon, 11 Nov 2024 16:47:41 -0700 Subject: [PATCH 1/2] add authorization header if included --- js-src/Websocket.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js-src/Websocket.ts b/js-src/Websocket.ts index abf9e33..58cf4f0 100644 --- a/js-src/Websocket.ts +++ b/js-src/Websocket.ts @@ -136,9 +136,15 @@ export class Websocket { if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) { console.log(`Sending auth request for channel ${channel.name}`) + if (this.options.bearerToken) { + this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken; + } + axios.post(this.options.authEndpoint, { socket_id: this.getSocketId(), channel_name: channel.name, + }, { + headers: this.options.auth.headers || {} }).then((response: AxiosResponse) => { console.log(`Subscribing to channels ${channel.name}`) From 99adec3fa4d54c8d94c1705d2e13b0f885079e8c Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Tue, 12 Nov 2024 10:55:48 -0700 Subject: [PATCH 2/2] Updated README.md to include example for authentication --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f1a705d..8e4568f 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,8 @@ window.Echo = new Echo({ broadcaster, // replace the placeholders host: 'wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage}', + authEndpoint: '{auth-url}/broadcasting/auth', // Optional: Use if you have a separate authentication endpoint + bearerToken: '{token}', // Optional: Use if you need a Bearer Token for authentication }); ```