From 0f73e54830ca9572879d01a3c24582a540d275b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 28 Mar 2025 07:56:59 +0100 Subject: [PATCH] Add device code oauth handling --- .../ui/thingconfiguration/SetupWizard.qml | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/nymea-app/ui/thingconfiguration/SetupWizard.qml b/nymea-app/ui/thingconfiguration/SetupWizard.qml index 01c496a8..75cb2644 100644 --- a/nymea-app/ui/thingconfiguration/SetupWizard.qml +++ b/nymea-app/ui/thingconfiguration/SetupWizard.qml @@ -57,7 +57,7 @@ Page { property int pairRequestId: 0 property var pairingTransactionId: null property int addRequestId: 0 - property var name: "" + property string name: "" property var params: [] function pairThing() { @@ -126,7 +126,7 @@ Page { print("New thing setup") internalPageStack.push(paramsPage) - // Reconfigure + // Reconfigure } else if (root.thing) { print("Existing thing") // There are params. Open params page in any case @@ -134,7 +134,7 @@ Page { print("Params:", root.thingClass.paramTypes.count) internalPageStack.push(paramsPage) - // No params... go straight to reconfigure/repair + // No params... go straight to reconfigure/repair } else { print("no params") switch (root.thingClass.setupMethod) { @@ -389,7 +389,7 @@ Page { id: paramRepeater model: engine.jsonRpcClient.ensureServerVersion("1.12") || d.thingDescriptor == null ? root.thingClass.paramTypes : null delegate: ParamDelegate { -// Layout.preferredHeight: 60 + // Layout.preferredHeight: 60 Layout.fillWidth: true enabled: !model.readOnly paramType: root.thingClass.paramTypes.get(index) @@ -558,13 +558,24 @@ Page { anchors.fill: parent url: oAuthPage.oAuthUrl + function finishProcess(url) { + print("Confirm pairing") + engine.thingManager.confirmPairing(d.pairingTransactionId, url) + busyIndicator.running = true + oAuthWebView.visible = false + } + onUrlChanged: { print("OAUTH URL changed", url) if (url.toString().indexOf("https://127.0.0.1") == 0) { - print("Redirect URL detected!"); - engine.thingManager.confirmPairing(d.pairingTransactionId, url) - busyIndicator.running = true - oAuthWebView.visible = false + print("Redirect URL detected!") + finishProcess(url) + } else if (url.toString().indexOf("device-complete") >= 0) { + // Unfortunatly device code authentication does not support redirect URLs like tado, + // yet this hack does work for this case when the authentication has been completed. + // The alternative would be a finished button below the webview. + print("Device code finish URL detected!") + finishProcess(url) } } }