added setup failure on missing client credentials
This commit is contained in:
parent
b9cd18a45e
commit
99194bded3
@ -79,8 +79,12 @@ void IntegrationPluginTado::confirmPairing(ThingPairingInfo *info, const QString
|
|||||||
// info->finish(success) will be called after the token has been received
|
// info->finish(success) will be called after the token has been received
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(tado, &Tado::apiCredentialsReceived, info, [password, tado] {
|
connect(tado, &Tado::apiCredentialsReceived, info, [info, password, tado] (bool success) {
|
||||||
tado->getToken(password);
|
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) {
|
connect(tado, &Tado::tokenReceived, info, [this, info, username, password](Tado::Token token) {
|
||||||
|
|||||||
@ -84,6 +84,7 @@ void Tado::getApiCredentials(const QString &url)
|
|||||||
// Check HTTP status code
|
// Check HTTP status code
|
||||||
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
||||||
qCWarning(dcTado()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcTado()) << "Request error:" << status << reply->errorString();
|
||||||
|
emit apiCredentialsReceived(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QRegExp filter;
|
QRegExp filter;
|
||||||
@ -92,30 +93,42 @@ void Tado::getApiCredentials(const QString &url)
|
|||||||
|
|
||||||
QStringList list = QString(reply->readAll()).split('\n');
|
QStringList list = QString(reply->readAll()).split('\n');
|
||||||
int index = list.indexOf(filter);
|
int index = list.indexOf(filter);
|
||||||
if (index == -1)
|
if (index == -1) {
|
||||||
|
qCWarning(dcTado()) << "GetApiCredenitals: Could not find the API url";
|
||||||
|
emit apiCredentialsReceived(false);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
m_baseControlUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"));;
|
m_baseControlUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"));;
|
||||||
qCDebug(dcTado()) << "Received control url" << m_baseControlUrl;
|
qCDebug(dcTado()) << "Received control url" << m_baseControlUrl;
|
||||||
filter.setPattern("*apiEndpoint*");
|
filter.setPattern("*apiEndpoint*");
|
||||||
index = list.indexOf(filter);
|
index = list.indexOf(filter);
|
||||||
if (index == -1)
|
if (index == -1) {
|
||||||
|
qCWarning(dcTado()) << "GetApiCredenitals: Could not find the authorization url";
|
||||||
|
emit apiCredentialsReceived(false);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
m_baseAuthorizationUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"))+"/token";
|
m_baseAuthorizationUrl = list.value(index).split(": ").last().remove(QRegExp("[,']"))+"/token";
|
||||||
qCDebug(dcTado()) << "Received auth url" << m_baseAuthorizationUrl;
|
qCDebug(dcTado()) << "Received auth url" << m_baseAuthorizationUrl;
|
||||||
filter.setPattern("*clientId*");
|
filter.setPattern("*clientId*");
|
||||||
index = list.indexOf(filter);
|
index = list.indexOf(filter);
|
||||||
if (index == -1)
|
if (index == -1) {
|
||||||
|
emit apiCredentialsReceived(false);
|
||||||
|
qCWarning(dcTado()) << "GetApiCredenitals: Could not find the client Id";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
m_clientId = list.value(index).split(": ").last().remove(QRegExp("[,']"));
|
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*");
|
filter.setPattern("*clientSecret*");
|
||||||
index = list.indexOf(filter);
|
index = list.indexOf(filter);
|
||||||
if (index == -1)
|
if (index == -1) {
|
||||||
|
qCWarning(dcTado()) << "GetApiCredenitals: Could not find the client secret";
|
||||||
|
emit apiCredentialsReceived(false);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
m_clientSecret = list.value(index).split(": ").last().remove(QRegExp("[,']"));
|
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;
|
m_apiAvailable = true;
|
||||||
emit apiCredentialsReceived();
|
emit apiCredentialsReceived(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ private:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionChanged(bool connected);
|
void connectionChanged(bool connected);
|
||||||
void apiCredentialsReceived();
|
void apiCredentialsReceived(bool success);
|
||||||
void authenticationStatusChanged(bool authenticated);
|
void authenticationStatusChanged(bool authenticated);
|
||||||
void requestExecuted(QUuid requestId, bool success);
|
void requestExecuted(QUuid requestId, bool success);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user