Desktop OIDC: open in system browser via window.open, revert to copy-paste
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.
This commit is contained in:
@@ -558,20 +558,22 @@ func main() {
|
|||||||
|
|
||||||
ws := loadWindowState()
|
ws := loadWindowState()
|
||||||
width, height := 1400, 900
|
width, height := 1400, 900
|
||||||
minWidth, minHeight := 1024, 700
|
if ws != nil {
|
||||||
|
width = ws.Width
|
||||||
|
height = ws.Height
|
||||||
|
}
|
||||||
|
|
||||||
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
window := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||||
Title: "Oikos",
|
Title: "Oikos",
|
||||||
Width: width,
|
Width: width,
|
||||||
Height: height,
|
Height: height,
|
||||||
MinWidth: minWidth,
|
MinWidth: 1024,
|
||||||
MinHeight: minHeight,
|
MinHeight: 700,
|
||||||
URL: "/?desktop=1",
|
URL: "/?desktop=1",
|
||||||
})
|
})
|
||||||
|
|
||||||
if ws != nil {
|
if ws != nil {
|
||||||
window.SetPosition(ws.X, ws.Y)
|
window.SetPosition(ws.X, ws.Y)
|
||||||
window.SetSize(ws.Width, ws.Height)
|
|
||||||
} else {
|
} else {
|
||||||
window.Center()
|
window.Center()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,14 @@ export async function startLogin(): Promise<void> {
|
|||||||
scope: 'openid profile email'
|
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<boolean> {
|
export async function handleCallback(code: string, returnedState: string): Promise<boolean> {
|
||||||
|
|||||||
@@ -67,27 +67,7 @@
|
|||||||
error = ''
|
error = ''
|
||||||
oidcLoggingIn = true
|
oidcLoggingIn = true
|
||||||
setConfig({ apiUrl: apiUrl.trim(), token: '' })
|
setConfig({ apiUrl: apiUrl.trim(), token: '' })
|
||||||
|
initConfig({ 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
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await startLogin()
|
await startLogin()
|
||||||
|
|||||||
Reference in New Issue
Block a user