some fixes to make oauth flow more friendly
This commit is contained in:
parent
96c0832686
commit
c26acdb2ae
src/librssguard
@ -297,6 +297,8 @@ void OAuth2Service::logout() {
|
||||
setTokensExpireIn(QDateTime());
|
||||
setAccessToken(QString());
|
||||
setRefreshToken(QString());
|
||||
|
||||
m_redirectionHandler->stop();
|
||||
}
|
||||
|
||||
void OAuth2Service::startRefreshTimer() {
|
||||
|
@ -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:
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,11 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent)
|
||||
void FormEditInoreaderAccount::apply() {
|
||||
bool editing_account = !applyInternal<InoreaderServiceRoot>();
|
||||
|
||||
// We copy credentials from testing OAuth to live OAuth.
|
||||
account<InoreaderServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
||||
account<InoreaderServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
||||
account<InoreaderServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
||||
if (!editing_account) {
|
||||
// We are creating new account.
|
||||
m_details->m_oauth->setParent(account<InoreaderServiceRoot>()->network());
|
||||
account<InoreaderServiceRoot>()->network()->setOauth(m_details->m_oauth);
|
||||
}
|
||||
|
||||
account<InoreaderServiceRoot>()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text());
|
||||
account<InoreaderServiceRoot>()->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();
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<RootItem*> getLabels();
|
||||
|
||||
QList<Message> 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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user