Some optimalizations on OAuth process.

This commit is contained in:
Martin Rotter 2017-12-15 09:11:07 +01:00
parent 4175dc2265
commit f23e1aec73
5 changed files with 14 additions and 5 deletions

View File

@ -26,6 +26,7 @@
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "network-web/networkfactory.h"
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
#include "services/inoreader/definitions.h" #include "services/inoreader/definitions.h"
@ -186,7 +187,10 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
qDebug() << "Token response:" << json_document.toJson(); qDebug() << "Token response:" << json_document.toJson();
if (root_obj.keys().contains("error")) { if (network_reply->error() != QNetworkReply::NetworkError::NoError) {
emit tokensRetrieveError(QString(), NetworkFactory::networkErrorText(network_reply->error()));
}
else if (root_obj.keys().contains("error")) {
QString error = root_obj.value("error").toString(); QString error = root_obj.value("error").toString();
QString error_description = root_obj.value("error_description").toString(); QString error_description = root_obj.value("error_description").toString();

View File

@ -164,11 +164,11 @@ void GmailServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
loadCacheFromFile(accountId()); loadCacheFromFile(accountId());
m_network->oauth()->login();
if (childCount() <= 1) { if (childCount() <= 1) {
syncIn(); syncIn();
} }
m_network->oauth()->login();
} }
void GmailServiceRoot::stop() { void GmailServiceRoot::stop() {

View File

@ -269,6 +269,8 @@ void GmailNetworkFactory::onTokensError(const QString& error, const QString& err
QSystemTrayIcon::Critical, QSystemTrayIcon::Critical,
nullptr, false, nullptr, false,
[this]() { [this]() {
m_oauth2->setAccessToken(QString());
m_oauth2->setRefreshToken(QString());
m_oauth2->login(); m_oauth2->login();
}); });
} }

View File

@ -122,11 +122,12 @@ void InoreaderServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
loadCacheFromFile(accountId()); loadCacheFromFile(accountId());
m_network->oauth()->login();
if (childCount() <= 1) { if (childCount() <= 1) {
syncIn(); syncIn();
} }
else {
m_network->oauth()->login();
}
} }
void InoreaderServiceRoot::stop() { void InoreaderServiceRoot::stop() {

View File

@ -283,6 +283,8 @@ void InoreaderNetworkFactory::onTokensError(const QString& error, const QString&
QSystemTrayIcon::Critical, QSystemTrayIcon::Critical,
nullptr, false, nullptr, false,
[this]() { [this]() {
m_oauth2->setAccessToken(QString());
m_oauth2->setRefreshToken(QString());
m_oauth2->login(); m_oauth2->login();
}); });
} }