From 99194bded3cc718b7ae1516554251931b4eac7f3 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Mon, 7 Dec 2020 09:19:36 +0100 Subject: [PATCH] added setup failure on missing client credentials --- tado/integrationplugintado.cpp | 8 ++++++-- tado/tado.cpp | 27 ++++++++++++++++++++------- tado/tado.h | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tado/integrationplugintado.cpp b/tado/integrationplugintado.cpp index 57232b66..024b0b86 100644 --- a/tado/integrationplugintado.cpp +++ b/tado/integrationplugintado.cpp @@ -79,8 +79,12 @@ void IntegrationPluginTado::confirmPairing(ThingPairingInfo *info, const QString // info->finish(success) will be called after the token has been received }); - connect(tado, &Tado::apiCredentialsReceived, info, [password, tado] { - tado->getToken(password); + connect(tado, &Tado::apiCredentialsReceived, info, [info, password, tado] (bool success) { + if (success) { + tado->getToken(password); + } else { + info->finish(Thing::ThingErrorAuthenticationFailure, "Client credentials not found, the plug-in version might be outdated."); + } }); connect(tado, &Tado::tokenReceived, info, [this, info, username, password](Tado::Token token) { diff --git a/tado/tado.cpp b/tado/tado.cpp index c52a7bee..16667a88 100644 --- a/tado/tado.cpp +++ b/tado/tado.cpp @@ -84,6 +84,7 @@ void Tado::getApiCredentials(const QString &url) // Check HTTP status code if (status != 200 || reply->error() != QNetworkReply::NoError) { qCWarning(dcTado()) << "Request error:" << status << reply->errorString(); + emit apiCredentialsReceived(false); return; } QRegExp filter; @@ -92,30 +93,42 @@ void Tado::getApiCredentials(const QString &url) QStringList list = QString(reply->readAll()).split('\n'); int index = list.indexOf(filter); - if (index == -1) + if (index == -1) { + qCWarning(dcTado()) << "GetApiCredenitals: Could not find the API url"; + emit apiCredentialsReceived(false); return; + } m_baseControlUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"));; qCDebug(dcTado()) << "Received control url" << m_baseControlUrl; filter.setPattern("*apiEndpoint*"); index = list.indexOf(filter); - if (index == -1) + if (index == -1) { + qCWarning(dcTado()) << "GetApiCredenitals: Could not find the authorization url"; + emit apiCredentialsReceived(false); return; + } m_baseAuthorizationUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"))+"/token"; qCDebug(dcTado()) << "Received auth url" << m_baseAuthorizationUrl; filter.setPattern("*clientId*"); index = list.indexOf(filter); - if (index == -1) + if (index == -1) { + emit apiCredentialsReceived(false); + qCWarning(dcTado()) << "GetApiCredenitals: Could not find the client Id"; return; + } m_clientId = list.value(index).split(": ").last().remove(QRegExp("[,']")); - qCDebug(dcTado()) << "Received client id" << m_clientId; + qCDebug(dcTado()) << "Received client id" << m_clientId.mid(0, 4)+"*****"; filter.setPattern("*clientSecret*"); index = list.indexOf(filter); - if (index == -1) + if (index == -1) { + qCWarning(dcTado()) << "GetApiCredenitals: Could not find the client secret"; + emit apiCredentialsReceived(false); return; + } m_clientSecret = list.value(index).split(": ").last().remove(QRegExp("[,']")); - qCDebug(dcTado()) << "Received client secret" << m_clientSecret; + qCDebug(dcTado()) << "Received client secret" << m_clientSecret.mid(0, 4)+"*****"; m_apiAvailable = true; - emit apiCredentialsReceived(); + emit apiCredentialsReceived(true); }); } diff --git a/tado/tado.h b/tado/tado.h index 3fe7fb78..5ba134c9 100644 --- a/tado/tado.h +++ b/tado/tado.h @@ -126,7 +126,7 @@ private: signals: void connectionChanged(bool connected); - void apiCredentialsReceived(); + void apiCredentialsReceived(bool success); void authenticationStatusChanged(bool authenticated); void requestExecuted(QUuid requestId, bool success);