Force cookies removal when testing inroeader login.
This commit is contained in:
parent
11e816bdf6
commit
9676c3fb9a
4 changed files with 59 additions and 5 deletions
|
|
@ -19,6 +19,8 @@
|
||||||
#include "gui/dialogs/oauthlogin.h"
|
#include "gui/dialogs/oauthlogin.h"
|
||||||
|
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
#include <QWebEngineCookieStore>
|
||||||
|
#include <QWebEngineProfile>
|
||||||
|
|
||||||
OAuthLogin::OAuthLogin(QWidget* parent) : QDialog(parent) {
|
OAuthLogin::OAuthLogin(QWidget* parent) : QDialog(parent) {
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
@ -28,6 +30,9 @@ OAuthLogin::OAuthLogin(QWidget* parent) : QDialog(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OAuthLogin::login(const QString& consentPageUrl, const QString& redirect_uri) {
|
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_redirectUri = redirect_uri;
|
||||||
m_ui.m_loginPage->setUrl(QUrl(consentPageUrl));
|
m_ui.m_loginPage->setUrl(QUrl(consentPageUrl));
|
||||||
exec();
|
exec();
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId,
|
OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId,
|
||||||
QString clientSecret, QString scope, QObject* parent)
|
QString clientSecret, QString scope, QObject* parent)
|
||||||
: QObject(parent), m_tokensExpireIn(QDateTime()) {
|
: QObject(parent), m_tokensExpireIn(QDateTime()) {
|
||||||
|
|
||||||
m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT);
|
m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT);
|
||||||
m_tokenGrantType = QSL("authorization_code");
|
m_tokenGrantType = QSL("authorization_code");
|
||||||
m_tokenUrl = QUrl(tokenUrl);
|
m_tokenUrl = QUrl(tokenUrl);
|
||||||
|
|
@ -75,11 +76,11 @@ void OAuth2Service::attachBearerHeader(QNetworkRequest& req) {
|
||||||
req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer().toLocal8Bit());
|
req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer().toLocal8Bit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OAuth2Service::setOAuthTokenGrantType(QString oAuthTokenGrantType) {
|
void OAuth2Service::setOAuthTokenGrantType(QString grant_type) {
|
||||||
m_tokenGrantType = oAuthTokenGrantType;
|
m_tokenGrantType = grant_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OAuth2Service::grant_type() {
|
QString OAuth2Service::oAuthTokenGrantType() {
|
||||||
return m_tokenGrantType;
|
return m_tokenGrantType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,6 +162,30 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* networkReply) {
|
||||||
networkReply->deleteLater();
|
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 {
|
QString OAuth2Service::refreshToken() const {
|
||||||
return m_refreshToken;
|
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() {
|
void OAuth2Service::retrieveAuthCode() {
|
||||||
QString auth_url = m_authUrl + QString("?client_id=%1&scope=%2&"
|
QString auth_url = m_authUrl + QString("?client_id=%1&scope=%2&"
|
||||||
"redirect_uri=%3&response_type=code&state=abcdef").arg(m_clientId,
|
"redirect_uri=%3&response_type=code&state=abcdef").arg(m_clientId,
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,20 @@ class OAuth2Service : public QObject {
|
||||||
void attachBearerHeader(QNetworkRequest& req);
|
void attachBearerHeader(QNetworkRequest& req);
|
||||||
|
|
||||||
void setOAuthTokenGrantType(QString grant_type);
|
void setOAuthTokenGrantType(QString grant_type);
|
||||||
QString grant_type();
|
QString oAuthTokenGrantType();
|
||||||
|
|
||||||
QString refreshToken() const;
|
QString refreshToken() const;
|
||||||
void setRefreshToken(const QString& refresh_token);
|
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:
|
signals:
|
||||||
void tokensReceived(QString access_token, QString refresh_token, int expires_in);
|
void tokensReceived(QString access_token, QString refresh_token, int expires_in);
|
||||||
void tokensRetrieveError(QString error, QString error_description);
|
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 true, if user is already logged in (final state).
|
||||||
// Returns false, if user is NOT logged in (asynchronous flow).
|
// Returns false, if user is NOT logged in (asynchronous flow).
|
||||||
bool login();
|
bool login();
|
||||||
|
void logout();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void cleanTokens();
|
void cleanTokens();
|
||||||
|
|
@ -92,8 +102,8 @@ class OAuth2Service : public QObject {
|
||||||
QDateTime m_tokensExpireIn;
|
QDateTime m_tokensExpireIn;
|
||||||
QString m_accessToken;
|
QString m_accessToken;
|
||||||
QString m_refreshToken;
|
QString m_refreshToken;
|
||||||
QString m_redirectUri;
|
|
||||||
QString m_tokenGrantType;
|
QString m_tokenGrantType;
|
||||||
|
QString m_redirectUri;
|
||||||
QString m_clientId;
|
QString m_clientId;
|
||||||
QString m_clientSecret;
|
QString m_clientSecret;
|
||||||
QUrl m_tokenUrl;
|
QUrl m_tokenUrl;
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,9 @@ void FormEditInoreaderAccount::onClickedOk() {
|
||||||
editing_account = false;
|
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()->setUsername(m_ui.m_txtUsername->lineEdit()->text());
|
||||||
m_editableRoot->network()->setBatchSize(m_ui.m_spinLimitMessages->value());
|
m_editableRoot->network()->setBatchSize(m_ui.m_spinLimitMessages->value());
|
||||||
m_editableRoot->saveAccountDataToDatabase();
|
m_editableRoot->saveAccountDataToDatabase();
|
||||||
|
|
@ -154,6 +157,10 @@ InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() {
|
||||||
void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root) {
|
void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root) {
|
||||||
setWindowTitle(tr("Edit existing Inoreader account"));
|
setWindowTitle(tr("Edit existing Inoreader account"));
|
||||||
m_editableRoot = existing_root;
|
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_txtUsername->lineEdit()->setText(existing_root->network()->userName());
|
||||||
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue