diff --git a/src/gui/dialogs/oauthlogin.cpp b/src/gui/dialogs/oauthlogin.cpp index 50612ba14..e04d67bec 100755 --- a/src/gui/dialogs/oauthlogin.cpp +++ b/src/gui/dialogs/oauthlogin.cpp @@ -19,6 +19,8 @@ #include "gui/dialogs/oauthlogin.h" #include +#include +#include OAuthLogin::OAuthLogin(QWidget* parent) : QDialog(parent) { m_ui.setupUi(this); @@ -28,6 +30,9 @@ OAuthLogin::OAuthLogin(QWidget* parent) : QDialog(parent) { } void OAuthLogin::login(const QString& consentPageUrl, const QString& redirect_uri) { + m_ui.m_loginPage->page()->profile()->clearHttpCache(); + m_ui.m_loginPage->page()->profile()->cookieStore()->deleteAllCookies(); + m_redirectUri = redirect_uri; m_ui.m_loginPage->setUrl(QUrl(consentPageUrl)); exec(); diff --git a/src/network-web/oauth2service.cpp b/src/network-web/oauth2service.cpp index 1f5710811..69349c87a 100755 --- a/src/network-web/oauth2service.cpp +++ b/src/network-web/oauth2service.cpp @@ -54,6 +54,7 @@ OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId, QString clientSecret, QString scope, QObject* parent) : QObject(parent), m_tokensExpireIn(QDateTime()) { + m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT); m_tokenGrantType = QSL("authorization_code"); m_tokenUrl = QUrl(tokenUrl); @@ -75,11 +76,11 @@ void OAuth2Service::attachBearerHeader(QNetworkRequest& req) { req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer().toLocal8Bit()); } -void OAuth2Service::setOAuthTokenGrantType(QString oAuthTokenGrantType) { - m_tokenGrantType = oAuthTokenGrantType; +void OAuth2Service::setOAuthTokenGrantType(QString grant_type) { + m_tokenGrantType = grant_type; } -QString OAuth2Service::grant_type() { +QString OAuth2Service::oAuthTokenGrantType() { return m_tokenGrantType; } @@ -161,6 +162,30 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* networkReply) { networkReply->deleteLater(); } +QString OAuth2Service::clientSecret() const { + return m_clientSecret; +} + +void OAuth2Service::setClientSecret(const QString& client_secret) { + m_clientSecret = client_secret; +} + +QString OAuth2Service::clientId() const { + return m_clientId; +} + +void OAuth2Service::setClientId(const QString& client_id) { + m_clientId = client_id; +} + +QString OAuth2Service::redirectUri() const { + return m_redirectUri; +} + +void OAuth2Service::setRedirectUri(const QString& redirect_uri) { + m_redirectUri = redirect_uri; +} + QString OAuth2Service::refreshToken() const { return m_refreshToken; } @@ -190,6 +215,13 @@ bool OAuth2Service::login() { } } +void OAuth2Service::logout() { + m_refreshToken = m_accessToken = QString(); + m_tokensExpireIn = QDateTime(); + + // TODO: zastavit timer na obnovení refresh tokenu? +} + void OAuth2Service::retrieveAuthCode() { QString auth_url = m_authUrl + QString("?client_id=%1&scope=%2&" "redirect_uri=%3&response_type=code&state=abcdef").arg(m_clientId, diff --git a/src/network-web/oauth2service.h b/src/network-web/oauth2service.h index 073b43b24..a56027629 100755 --- a/src/network-web/oauth2service.h +++ b/src/network-web/oauth2service.h @@ -57,11 +57,20 @@ class OAuth2Service : public QObject { void attachBearerHeader(QNetworkRequest& req); void setOAuthTokenGrantType(QString grant_type); - QString grant_type(); + QString oAuthTokenGrantType(); QString refreshToken() const; void setRefreshToken(const QString& refresh_token); + QString redirectUri() const; + void setRedirectUri(const QString& redirect_uri); + + QString clientId() const; + void setClientId(const QString& client_id); + + QString clientSecret() const; + void setClientSecret(const QString& client_secret); + signals: void tokensReceived(QString access_token, QString refresh_token, int expires_in); void tokensRetrieveError(QString error, QString error_description); @@ -83,6 +92,7 @@ class OAuth2Service : public QObject { // Returns true, if user is already logged in (final state). // Returns false, if user is NOT logged in (asynchronous flow). bool login(); + void logout(); private slots: void cleanTokens(); @@ -92,8 +102,8 @@ class OAuth2Service : public QObject { QDateTime m_tokensExpireIn; QString m_accessToken; QString m_refreshToken; - QString m_redirectUri; QString m_tokenGrantType; + QString m_redirectUri; QString m_clientId; QString m_clientSecret; QUrl m_tokenUrl; diff --git a/src/services/inoreader/gui/formeditinoreaderaccount.cpp b/src/services/inoreader/gui/formeditinoreaderaccount.cpp index bdf8bcde4..69f951ab0 100755 --- a/src/services/inoreader/gui/formeditinoreaderaccount.cpp +++ b/src/services/inoreader/gui/formeditinoreaderaccount.cpp @@ -80,6 +80,9 @@ void FormEditInoreaderAccount::onClickedOk() { editing_account = false; } + m_editableRoot->network()->oauth()->setClientId(m_ui.m_txtAppId->lineEdit()->text()); + m_editableRoot->network()->oauth()->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text()); + m_editableRoot->network()->oauth()->setRedirectUri(m_ui.m_txtRedirectUrl->lineEdit()->text()); m_editableRoot->network()->setUsername(m_ui.m_txtUsername->lineEdit()->text()); m_editableRoot->network()->setBatchSize(m_ui.m_spinLimitMessages->value()); m_editableRoot->saveAccountDataToDatabase(); @@ -154,6 +157,10 @@ InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() { void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root) { setWindowTitle(tr("Edit existing Inoreader account")); m_editableRoot = existing_root; + + m_ui.m_txtAppId->lineEdit()->setText(existing_root->network()->oauth()->clientId()); + m_ui.m_txtAppKey->lineEdit()->setText(existing_root->network()->oauth()->clientSecret()); + m_ui.m_txtRedirectUrl->lineEdit()->setText(existing_root->network()->oauth()->redirectUri()); m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->userName()); m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());