From 030b8ed4fd6cd36281682de723993a6949d696f8 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 24 Sep 2019 21:22:11 -0700 Subject: [PATCH] Change to support websocket JWT connections --- .../Controllers/Api/Client/Servers/WebsocketController.php | 1 + resources/scripts/plugins/Websocket.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/WebsocketController.php b/app/Http/Controllers/Api/Client/Servers/WebsocketController.php index 3a4e716a..c597ab8a 100644 --- a/app/Http/Controllers/Api/Client/Servers/WebsocketController.php +++ b/app/Http/Controllers/Api/Client/Servers/WebsocketController.php @@ -63,6 +63,7 @@ class WebsocketController extends ClientApiController ->expiresAt($now->addMinutes(15)->getTimestamp()) ->withClaim('user_id', $request->user()->id) ->withClaim('server_uuid', $server->uuid) + ->withClaim('permissions', ['connect', 'send-command', 'send-power']) ->getToken($signer, new Key($server->node->daemonSecret)); $socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress()); diff --git a/resources/scripts/plugins/Websocket.ts b/resources/scripts/plugins/Websocket.ts index 2c4ed24e..682c9688 100644 --- a/resources/scripts/plugins/Websocket.ts +++ b/resources/scripts/plugins/Websocket.ts @@ -25,7 +25,7 @@ export class Websocket extends EventEmitter { // Connects to the websocket instance and sets the token for the initial request. connect (url: string) { this.url = url; - this.socket = new Sockette(url, { + this.socket = new Sockette(`${this.url}?token=${this.token}`, { onmessage: e => { try { let { event, args } = JSON.parse(e.data); @@ -75,7 +75,6 @@ export class Websocket extends EventEmitter { this.socket && this.socket.send(JSON.stringify({ event, args: Array.isArray(payload) ? payload : [ payload ], - token: this.token || '', })); } }