Change to support websocket JWT connections

This commit is contained in:
Dane Everitt 2019-09-24 21:22:11 -07:00
parent 18c4b951e6
commit 030b8ed4fd
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 2 additions and 2 deletions

View File

@ -63,6 +63,7 @@ class WebsocketController extends ClientApiController
->expiresAt($now->addMinutes(15)->getTimestamp()) ->expiresAt($now->addMinutes(15)->getTimestamp())
->withClaim('user_id', $request->user()->id) ->withClaim('user_id', $request->user()->id)
->withClaim('server_uuid', $server->uuid) ->withClaim('server_uuid', $server->uuid)
->withClaim('permissions', ['connect', 'send-command', 'send-power'])
->getToken($signer, new Key($server->node->daemonSecret)); ->getToken($signer, new Key($server->node->daemonSecret));
$socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress()); $socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress());

View File

@ -25,7 +25,7 @@ export class Websocket extends EventEmitter {
// Connects to the websocket instance and sets the token for the initial request. // Connects to the websocket instance and sets the token for the initial request.
connect (url: string) { connect (url: string) {
this.url = url; this.url = url;
this.socket = new Sockette(url, { this.socket = new Sockette(`${this.url}?token=${this.token}`, {
onmessage: e => { onmessage: e => {
try { try {
let { event, args } = JSON.parse(e.data); let { event, args } = JSON.parse(e.data);
@ -75,7 +75,6 @@ export class Websocket extends EventEmitter {
this.socket && this.socket.send(JSON.stringify({ this.socket && this.socket.send(JSON.stringify({
event, event,
args: Array.isArray(payload) ? payload : [ payload ], args: Array.isArray(payload) ? payload : [ payload ],
token: this.token || '',
})); }));
} }
} }