diff --git a/src/librssguard/network-web/oauth2service.cpp b/src/librssguard/network-web/oauth2service.cpp index 997caf6d5..d2857e19d 100644 --- a/src/librssguard/network-web/oauth2service.cpp +++ b/src/librssguard/network-web/oauth2service.cpp @@ -297,6 +297,8 @@ void OAuth2Service::logout() { setTokensExpireIn(QDateTime()); setAccessToken(QString()); setRefreshToken(QString()); + + m_redirectionHandler->stop(); } void OAuth2Service::startRefreshTimer() { diff --git a/src/librssguard/network-web/oauth2service.h b/src/librssguard/network-web/oauth2service.h index a58000005..835f7d1b5 100644 --- a/src/librssguard/network-web/oauth2service.h +++ b/src/librssguard/network-web/oauth2service.h @@ -92,6 +92,7 @@ class OAuth2Service : public QObject { // NOTE: This can be called ONLY on main GUI thread, // because widgets may be displayed. bool login(); + void logout(); private slots: diff --git a/src/librssguard/network-web/oauthhttphandler.cpp b/src/librssguard/network-web/oauthhttphandler.cpp index ca07f08bb..d8b824092 100644 --- a/src/librssguard/network-web/oauthhttphandler.cpp +++ b/src/librssguard/network-web/oauthhttphandler.cpp @@ -21,7 +21,7 @@ OAuthHttpHandler::OAuthHttpHandler(const QString& success_text, QObject* parent) OAuthHttpHandler::~OAuthHttpHandler() { if (m_httpServer.isListening()) { qWarningNN << LOGSEC_OAUTH << "Redirection OAuth handler is listening. Stopping it now."; - m_httpServer.close(); + stop(); } } @@ -41,19 +41,17 @@ void OAuthHttpHandler::setListenAddressPort(const QString& full_uri) { listen_address = QHostAddress(url.host()); } - if (listen_address == m_listenAddress && - m_listenPort == url.port() && - m_httpServer.isListening()) { + if (listen_address == m_listenAddress && url.port() == m_listenPort && m_httpServer.isListening()) { // NOTE: We do not need to change listener's settings or re-start it. return; } if (m_httpServer.isListening()) { qWarningNN << LOGSEC_OAUTH << "Redirection OAuth handler is listening. Stopping it now."; - m_httpServer.close(); + stop(); } - if (!m_httpServer.listen(m_listenAddress, m_listenPort)) { + if (!m_httpServer.listen(listen_address, listen_port)) { qCriticalNN << LOGSEC_OAUTH << "OAuth redirect handler FAILED TO START TO LISTEN on address" << QUOTE_W_SPACE(m_listenAddress.toString()) @@ -337,3 +335,11 @@ bool OAuthHttpHandler::QHttpRequest::readHeader(QTcpSocket* socket) { return false; } + +void OAuthHttpHandler::stop() { + m_httpServer.close(); + m_connectedClients.clear(); + m_listenAddress = QHostAddress(); + m_listenPort = 0; + m_listenAddressPort = QString(); +} diff --git a/src/librssguard/network-web/oauthhttphandler.h b/src/librssguard/network-web/oauthhttphandler.h index f6e58bd6f..42a0d1cec 100644 --- a/src/librssguard/network-web/oauthhttphandler.h +++ b/src/librssguard/network-web/oauthhttphandler.h @@ -17,6 +17,9 @@ class OAuthHttpHandler : public QObject { bool isListening() const; + // Stops server and clear all connections. + void stop(); + // Returns listening portnumber. quint16 listenPort() const; diff --git a/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp b/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp index ae1b36868..a2b10e9fe 100644 --- a/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp +++ b/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp @@ -11,7 +11,7 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent) : QWidget(parent), m_oauth(new OAuth2Service(GMAIL_OAUTH_AUTH_URL, GMAIL_OAUTH_TOKEN_URL, - QString(), QString(), GMAIL_OAUTH_SCOPE, this)) { + {}, {}, GMAIL_OAUTH_SCOPE, this)) { m_ui.setupUi(this); GuiUtilities::setLabelAsNotice(*m_ui.m_lblInfo, true); diff --git a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp index 7d6573a4e..3f60a7d45 100644 --- a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp +++ b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp @@ -28,7 +28,7 @@ GmailNetworkFactory::GmailNetworkFactory(QObject* parent) : QObject(parent), m_service(nullptr), m_username(QString()), m_batchSize(GMAIL_DEFAULT_BATCH_SIZE), m_oauth2(new OAuth2Service(GMAIL_OAUTH_AUTH_URL, GMAIL_OAUTH_TOKEN_URL, - QString(), QString(), GMAIL_OAUTH_SCOPE, this)) { + {}, {}, GMAIL_OAUTH_SCOPE, this)) { initializeOauth(); } diff --git a/src/librssguard/services/inoreader/gui/formeditinoreaderaccount.cpp b/src/librssguard/services/inoreader/gui/formeditinoreaderaccount.cpp index 0e0a58c07..1caf3a025 100644 --- a/src/librssguard/services/inoreader/gui/formeditinoreaderaccount.cpp +++ b/src/librssguard/services/inoreader/gui/formeditinoreaderaccount.cpp @@ -23,10 +23,11 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) void FormEditInoreaderAccount::apply() { bool editing_account = !applyInternal(); - // We copy credentials from testing OAuth to live OAuth. - account()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken()); - account()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken()); - account()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn()); + if (!editing_account) { + // We are creating new account. + m_details->m_oauth->setParent(account()->network()); + account()->network()->setOauth(m_details->m_oauth); + } account()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text()); account()->network()->oauth()->setClientSecret(m_details->m_ui.m_txtAppKey->lineEdit()->text()); @@ -48,6 +49,8 @@ void FormEditInoreaderAccount::setEditableAccount(ServiceRoot* editable_account) FormAccountDetails::setEditableAccount(editable_account); if (m_details->m_oauth != nullptr) { + // Remove OAuth meant for new account. + // We are load existing account and we will use its OAuth. m_details->m_oauth->logout(); m_details->m_oauth->deleteLater(); } diff --git a/src/librssguard/services/inoreader/gui/inoreaderaccountdetails.cpp b/src/librssguard/services/inoreader/gui/inoreaderaccountdetails.cpp index 5067fa071..d28d316ea 100755 --- a/src/librssguard/services/inoreader/gui/inoreaderaccountdetails.cpp +++ b/src/librssguard/services/inoreader/gui/inoreaderaccountdetails.cpp @@ -11,8 +11,7 @@ InoreaderAccountDetails::InoreaderAccountDetails(QWidget* parent) : QWidget(parent), m_oauth(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL, - INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, - INOREADER_OAUTH_SCOPE, this)) { + {}, {}, INOREADER_OAUTH_SCOPE, this)) { m_ui.setupUi(this); GuiUtilities::setLabelAsNotice(*m_ui.m_lblInfo, true); @@ -58,13 +57,7 @@ InoreaderAccountDetails::InoreaderAccountDetails(QWidget* parent) } void InoreaderAccountDetails::testSetup() { - if (m_oauth->clientId() != m_ui.m_txtAppId->lineEdit()->text() || - m_oauth->clientSecret() != m_ui.m_txtAppKey->lineEdit()->text() || - m_oauth->redirectUrl() != m_ui.m_txtRedirectUrl->lineEdit()->text()) { - // User changed some important settings. Log out. - m_oauth->logout(); - } - + m_oauth->logout(); m_oauth->setClientId(m_ui.m_txtAppId->lineEdit()->text()); m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text()); m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text()); diff --git a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp index b9d853eea..acf1d3284 100644 --- a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp +++ b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp @@ -28,7 +28,7 @@ InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent), m_service(nullptr), m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL, - INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE, this)) { + {}, {}, INOREADER_OAUTH_SCOPE, this)) { initializeOauth(); } @@ -444,3 +444,7 @@ RootItem* InoreaderNetworkFactory::decodeFeedCategoriesData(const QString& categ return parent; } + +void InoreaderNetworkFactory::setOauth(OAuth2Service* oauth) { + m_oauth2 = oauth; +} diff --git a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.h b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.h index 1891b8a5f..f15fe4231 100644 --- a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.h +++ b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.h @@ -25,6 +25,7 @@ class InoreaderNetworkFactory : public QObject { void setService(InoreaderServiceRoot* service); OAuth2Service* oauth() const; + void setOauth(OAuth2Service* oauth); QString userName() const; void setUsername(const QString& username); @@ -39,11 +40,8 @@ class InoreaderNetworkFactory : public QObject { RootItem* feedsCategories(bool obtain_icons); QList getLabels(); - QList messages(ServiceRoot* root, const QString& stream_id, Feed::Status& error); - QNetworkReply::NetworkError editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids); - QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids); QNetworkReply::NetworkError markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids);