From 56e509d506f5cc035a6e4b98b8c0fc39af2e5fdc Mon Sep 17 00:00:00 2001 From: dtoro Date: Tue, 14 Jul 2026 00:00:24 +0200 Subject: [PATCH] Desktop OIDC: open in system browser via window.open, revert to copy-paste MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The local HTTP server approach (fetch to 127.0.0.1) doesn't work in the Wails webview. Simplify: use window.open() to launch OIDC in the real browser. After authentication, the callback page at the server shows the token. User copies and pastes into the Token tab. Also fix: SetSize before app.Run() crashes with nil pointer — use WebviewWindowOptions width/height directly from restored state. --- cmd/desktop/main.go | 10 ++++++---- web/src/lib/oidc.ts | 9 ++++++++- web/src/pages/Config.svelte | 22 +--------------------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/cmd/desktop/main.go b/cmd/desktop/main.go index 3c09dd3..fb87686 100644 --- a/cmd/desktop/main.go +++ b/cmd/desktop/main.go @@ -558,20 +558,22 @@ func main() { ws := loadWindowState() width, height := 1400, 900 - minWidth, minHeight := 1024, 700 + if ws != nil { + width = ws.Width + height = ws.Height + } window := app.Window.NewWithOptions(application.WebviewWindowOptions{ Title: "Oikos", Width: width, Height: height, - MinWidth: minWidth, - MinHeight: minHeight, + MinWidth: 1024, + MinHeight: 700, URL: "/?desktop=1", }) if ws != nil { window.SetPosition(ws.X, ws.Y) - window.SetSize(ws.Width, ws.Height) } else { window.Center() } diff --git a/web/src/lib/oidc.ts b/web/src/lib/oidc.ts index 68d7f51..c7ade97 100644 --- a/web/src/lib/oidc.ts +++ b/web/src/lib/oidc.ts @@ -101,7 +101,14 @@ export async function startLogin(): Promise { scope: 'openid profile email' }) - location.href = `${cfg.authorization_endpoint.replace(/\/$/, '')}/?${params}` + const authURL = `${cfg.authorization_endpoint.replace(/\/$/, '')}/?${params}` + + if (isDesktop) { + window.open(authURL, '_blank', 'width=800,height=700') + throw new Error('Login opened in your browser. After authenticating, copy the token and paste it into the Token tab.') + } + + location.href = authURL } export async function handleCallback(code: string, returnedState: string): Promise { diff --git a/web/src/pages/Config.svelte b/web/src/pages/Config.svelte index 6959a48..1cbfb25 100644 --- a/web/src/pages/Config.svelte +++ b/web/src/pages/Config.svelte @@ -67,27 +67,7 @@ error = '' oidcLoggingIn = true setConfig({ apiUrl: apiUrl.trim(), token: '' }) - - const isDesktop = new URLSearchParams(location.search).has('desktop') - - if (isDesktop) { - try { - const resp = await fetch(`http://127.0.0.1:18901/oidc/login?apiUrl=${encodeURIComponent(apiUrl.trim())}`) - const data = await resp.json() - if (data.token) { - setConfig({ apiUrl: apiUrl.trim(), token: data.token }) - initConfig({ apiUrl: apiUrl.trim(), token: data.token }) - oidcLoggingIn = false - onConnected() - return - } - error = data.error || 'Login failed' - } catch (e: any) { - error = e.message || 'Could not reach OIDC service' - } - oidcLoggingIn = false - return - } + initConfig({ apiUrl: apiUrl.trim(), token: '' }) try { await startLogin()