Add support for OAuth when setting up things
This commit is contained in:
parent
c38a4ba056
commit
5c2e288999
@ -297,6 +297,7 @@ void DeviceManager::pairDeviceResponse(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void DeviceManager::confirmPairingResponse(const QVariantMap ¶ms)
|
void DeviceManager::confirmPairingResponse(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
qDebug() << "ConfirmPairingResponse" << params;
|
||||||
emit confirmPairingReply(params.value("params").toMap());
|
emit confirmPairingReply(params.value("params").toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,6 +363,16 @@ void DeviceManager::pairDevice(const QUuid &deviceClassId, const QUuid &deviceDe
|
|||||||
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceManager::pairDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams)
|
||||||
|
{
|
||||||
|
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("name", name);
|
||||||
|
params.insert("deviceClassId", deviceClassId.toString());
|
||||||
|
params.insert("deviceParams", deviceParams);
|
||||||
|
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceManager::confirmPairing(const QUuid &pairingTransactionId, const QString &secret)
|
void DeviceManager::confirmPairing(const QUuid &pairingTransactionId, const QString &secret)
|
||||||
{
|
{
|
||||||
qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString();
|
qDebug() << "JsonRpc: confirm pairing" << pairingTransactionId.toString();
|
||||||
|
|||||||
@ -69,6 +69,7 @@ public:
|
|||||||
Q_INVOKABLE void addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE void addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
||||||
Q_INVOKABLE void addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE void addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams);
|
||||||
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name);
|
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name);
|
||||||
|
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
||||||
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||||
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
||||||
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
||||||
|
|||||||
@ -492,6 +492,8 @@ DeviceClass::SetupMethod JsonTypes::stringToSetupMethod(const QString &setupMeth
|
|||||||
return DeviceClass::SetupMethodEnterPin;
|
return DeviceClass::SetupMethodEnterPin;
|
||||||
} else if (setupMethodString == "SetupMethodPushButton") {
|
} else if (setupMethodString == "SetupMethodPushButton") {
|
||||||
return DeviceClass::SetupMethodPushButton;
|
return DeviceClass::SetupMethodPushButton;
|
||||||
|
} else if (setupMethodString == "SetupMethodOAuth") {
|
||||||
|
return DeviceClass::SetupMethodOAuth;
|
||||||
}
|
}
|
||||||
return DeviceClass::SetupMethodJustAdd;
|
return DeviceClass::SetupMethodJustAdd;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,8 @@ public:
|
|||||||
SetupMethodJustAdd,
|
SetupMethodJustAdd,
|
||||||
SetupMethodDisplayPin,
|
SetupMethodDisplayPin,
|
||||||
SetupMethodEnterPin,
|
SetupMethodEnterPin,
|
||||||
SetupMethodPushButton
|
SetupMethodPushButton,
|
||||||
|
SetupMethodOAuth,
|
||||||
};
|
};
|
||||||
Q_ENUM(SetupMethod)
|
Q_ENUM(SetupMethod)
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import QtQuick.Layouts 1.1
|
|||||||
import QtQuick.Controls 2.1
|
import QtQuick.Controls 2.1
|
||||||
import QtQuick.Controls.Material 2.1
|
import QtQuick.Controls.Material 2.1
|
||||||
import Nymea 1.0
|
import Nymea 1.0
|
||||||
|
import QtWebView 1.1
|
||||||
|
|
||||||
import "../components"
|
import "../components"
|
||||||
import "../delegates"
|
import "../delegates"
|
||||||
|
|
||||||
@ -60,18 +62,29 @@ Page {
|
|||||||
target: engine.deviceManager
|
target: engine.deviceManager
|
||||||
onPairDeviceReply: {
|
onPairDeviceReply: {
|
||||||
busyOverlay.shown = false
|
busyOverlay.shown = false
|
||||||
|
if (params["deviceError"] !== "DeviceErrorNoError") {
|
||||||
|
busyOverlay.shown = false;
|
||||||
|
internalPageStack.push(resultsPage, {success: false})
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
d.pairingTransactionId = params["pairingTransactionId"];
|
||||||
|
|
||||||
switch (params["setupMethod"]) {
|
switch (params["setupMethod"]) {
|
||||||
case "SetupMethodPushButton":
|
case "SetupMethodPushButton":
|
||||||
d.pairingTransactionId = params["pairingTransactionId"];
|
|
||||||
print("response", params["displayMessage"], d.pairingTransactionId)
|
print("response", params["displayMessage"], d.pairingTransactionId)
|
||||||
internalPageStack.push(pairingPageComponent, {text: params["displayMessage"]})
|
internalPageStack.push(pairingPageComponent, {text: params["displayMessage"]})
|
||||||
break;
|
break;
|
||||||
case "SetupMethodDisplayPin":
|
case "SetupMethodDisplayPin":
|
||||||
d.pairingTransactionId = params["pairingTransactionId"];
|
|
||||||
internalPageStack.push(pairingPageComponent, {text: params["displayMessage"], setupMethod: params["setupMethod"]})
|
internalPageStack.push(pairingPageComponent, {text: params["displayMessage"], setupMethod: params["setupMethod"]})
|
||||||
break;
|
break;
|
||||||
|
case "SetupMethodOAuth":
|
||||||
|
print("OAuth URL:", params["oAuthUrl"]);
|
||||||
|
internalPageStack.push(oAuthPageComponent, {oAuthUrl: params["oAuthUrl"]})
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print("Setup method", params["setupMethod"], "not handled");
|
print("Setup method reply not handled:", JSON.stringify(params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onConfirmPairingReply: {
|
onConfirmPairingReply: {
|
||||||
@ -364,7 +377,23 @@ Page {
|
|||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text);
|
case 4:
|
||||||
|
if (root.device) {
|
||||||
|
// if (d.deviceDescriptor) {
|
||||||
|
// engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text);
|
||||||
|
// } else {
|
||||||
|
// engine.deviceManager.pairDevice(root.deviceClass.id, nameTextField.text, params);
|
||||||
|
// }
|
||||||
|
console.warn("Unhandle setupMethod!")
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (d.deviceDescriptor) {
|
||||||
|
engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text);
|
||||||
|
} else {
|
||||||
|
engine.deviceManager.pairDevice(root.deviceClass.id, nameTextField.text, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,6 +451,27 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: oAuthPageComponent
|
||||||
|
Page {
|
||||||
|
id: oAuthPage
|
||||||
|
property alias oAuthUrl: oAuthWebView.url
|
||||||
|
|
||||||
|
WebView {
|
||||||
|
id: oAuthWebView
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
onUrlChanged: {
|
||||||
|
print("OAUTH URL changed", url)
|
||||||
|
if (url.toString().indexOf("https://127.0.0.1") == 0) {
|
||||||
|
print("Redirect URL detected!");
|
||||||
|
engine.deviceManager.confirmPairing(d.pairingTransactionId, url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: resultsPage
|
id: resultsPage
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user