From 2bfc0400105105e80ab818ed336fe0b444a1d457 Mon Sep 17 00:00:00 2001 From: Seth Van Niekerk Date: Thu, 2 Oct 2025 09:02:29 -0400 Subject: [PATCH] Selkies Checkpoint 7 - Auth --- Dockerfile | 8 +++-- icons/auth-fix.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 icons/auth-fix.js diff --git a/Dockerfile b/Dockerfile index a785eaa..67bf329 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,8 @@ ENV \ SELKIES_AUDIO_ENABLED="false" \ SELKIES_GAMEPAD_ENABLED="false" \ SELKIES_UI_SIDEBAR_SHOW_GAMEPADS="false" \ - SELKIES_UI_SIDEBAR_SHOW_AUDIO_SETTINGS="false" + SELKIES_UI_SIDEBAR_SHOW_AUDIO_SETTINGS="false" \ + CUSTOM_USER="runelite" RUN apt-get update && apt-get install -y --no-install-recommends \ default-jre \ @@ -33,7 +34,7 @@ RUN usermod -a -G audio abc # Add RuneLite icon for Selkies interface and favicon COPY icons/ /usr/share/selkies/www/ -# Inject iOS webapp meta tags into Selkies HTML (if index.html exists) +# Inject iOS webapp meta tags and auth fix into Selkies HTML (if index.html exists) RUN if [ -f /usr/share/selkies/www/index.html ]; then \ sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ @@ -42,7 +43,8 @@ RUN if [ -f /usr/share/selkies/www/index.html ]; then \ sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ - sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html; \ + sed -i '/<\/head>/i\' /usr/share/selkies/www/index.html && \ + echo "" ; \ fi diff --git a/icons/auth-fix.js b/icons/auth-fix.js new file mode 100644 index 0000000..9cd9816 --- /dev/null +++ b/icons/auth-fix.js @@ -0,0 +1,89 @@ +// Simple fix for HTTP Basic Auth WebSocket connection issues +// Only prevents initial failed connections, allows normal operation after auth + +(function() { + 'use strict'; + + // Quick check if we're already authenticated + let authChecked = false; + let isAuthenticated = false; + + // Store original WebSocket + const OriginalWebSocket = window.WebSocket; + + // Simple auth check + function quickAuthCheck() { + if (authChecked) return Promise.resolve(isAuthenticated); + + return fetch(window.location.href, { + method: 'HEAD', + credentials: 'same-origin' + }).then(response => { + authChecked = true; + isAuthenticated = response.ok && response.status !== 401; + return isAuthenticated; + }).catch(() => { + authChecked = true; + isAuthenticated = false; + return false; + }); + } + + // Override WebSocket constructor + window.WebSocket = function(url, protocols) { + // If we haven't checked auth yet, do a quick check + if (!authChecked) { + quickAuthCheck().then(authenticated => { + if (!authenticated) { + // If not authenticated, wait a bit and try again + setTimeout(() => { + window.location.reload(); + }, 2000); + } + }); + } + + // If we're authenticated or auth check passed, create WebSocket normally + if (isAuthenticated || authChecked) { + return new OriginalWebSocket(url, protocols); + } + + // Otherwise, create a dummy WebSocket that will be replaced + const ws = this; + ws.readyState = OriginalWebSocket.CONNECTING; + ws.bufferedAmount = 0; + ws.extensions = ''; + ws.protocol = ''; + ws.url = url; + ws.onopen = null; + ws.onclose = null; + ws.onerror = null; + ws.onmessage = null; + ws.close = function() {}; + ws.send = function() {}; + + // Check auth and replace with real WebSocket when ready + quickAuthCheck().then(authenticated => { + if (authenticated) { + const realWs = new OriginalWebSocket(url, protocols); + + // Copy event handlers + realWs.onopen = ws.onopen; + realWs.onclose = ws.onclose; + realWs.onerror = ws.onerror; + realWs.onmessage = ws.onmessage; + + // Replace methods and properties + Object.setPrototypeOf(ws, realWs); + Object.assign(ws, realWs); + } + }); + + return ws; + }; + + // Copy static properties + Object.setPrototypeOf(window.WebSocket, OriginalWebSocket); + Object.assign(window.WebSocket, OriginalWebSocket); + +})(); \ No newline at end of file