even better behavior for oauth
This commit is contained in:
parent
c26acdb2ae
commit
297c020d70
7 changed files with 31 additions and 22 deletions
|
@ -22,10 +22,15 @@ FormEditGmailAccount::FormEditGmailAccount(QWidget* parent)
|
||||||
void FormEditGmailAccount::apply() {
|
void FormEditGmailAccount::apply() {
|
||||||
bool editing_account = !applyInternal<GmailServiceRoot>();
|
bool editing_account = !applyInternal<GmailServiceRoot>();
|
||||||
|
|
||||||
// We copy credentials from testing OAuth to live OAuth.
|
if (!editing_account) {
|
||||||
account<GmailServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
// We transfer refresh token to avoid the need to login once more,
|
||||||
account<GmailServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
// then we delete testing OAuth service.
|
||||||
account<GmailServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
account<GmailServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
||||||
|
account<GmailServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
||||||
|
account<GmailServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
||||||
|
m_details->m_oauth->logout();
|
||||||
|
m_details->m_oauth->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
account<GmailServiceRoot>()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text());
|
account<GmailServiceRoot>()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text());
|
||||||
account<GmailServiceRoot>()->network()->oauth()->setClientSecret(m_details->m_ui.m_txtAppKey->lineEdit()->text());
|
account<GmailServiceRoot>()->network()->oauth()->setClientSecret(m_details->m_ui.m_txtAppKey->lineEdit()->text());
|
||||||
|
@ -47,6 +52,7 @@ void FormEditGmailAccount::setEditableAccount(ServiceRoot* editable_account) {
|
||||||
FormAccountDetails::setEditableAccount(editable_account);
|
FormAccountDetails::setEditableAccount(editable_account);
|
||||||
|
|
||||||
if (m_details->m_oauth != nullptr) {
|
if (m_details->m_oauth != nullptr) {
|
||||||
|
// We will use live OAuth service for testing.
|
||||||
m_details->m_oauth->logout();
|
m_details->m_oauth->logout();
|
||||||
m_details->m_oauth->deleteLater();
|
m_details->m_oauth->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,10 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent)
|
||||||
m_ui.m_spinLimitMessages->setMinimum(GMAIL_MIN_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setMinimum(GMAIL_MIN_BATCH_SIZE);
|
||||||
m_ui.m_spinLimitMessages->setMaximum(GMAIL_MAX_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setMaximum(GMAIL_MAX_BATCH_SIZE);
|
||||||
|
|
||||||
checkUsername(m_ui.m_txtUsername->lineEdit()->text());
|
emit m_ui.m_txtUsername->lineEdit()->textChanged(m_ui.m_txtUsername->lineEdit()->text());
|
||||||
|
emit m_ui.m_txtAppId->lineEdit()->textChanged(m_ui.m_txtAppId->lineEdit()->text());
|
||||||
|
emit m_ui.m_txtAppKey->lineEdit()->textChanged(m_ui.m_txtAppKey->lineEdit()->text());
|
||||||
|
|
||||||
m_ui.m_txtAppId->lineEdit()->clear();
|
|
||||||
m_ui.m_txtAppKey->lineEdit()->clear();
|
|
||||||
m_ui.m_txtRedirectUrl->lineEdit()->setText(QString(OAUTH_REDIRECT_URI) +
|
m_ui.m_txtRedirectUrl->lineEdit()->setText(QString(OAUTH_REDIRECT_URI) +
|
||||||
QL1C(':') +
|
QL1C(':') +
|
||||||
QString::number(OAUTH_REDIRECT_URI_PORT));
|
QString::number(OAUTH_REDIRECT_URI_PORT));
|
||||||
|
@ -54,13 +54,7 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void GmailAccountDetails::testSetup() {
|
void GmailAccountDetails::testSetup() {
|
||||||
if (m_oauth->clientId() != m_ui.m_txtAppId->lineEdit()->text() ||
|
m_oauth->logout();
|
||||||
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->setClientId(m_ui.m_txtAppId->lineEdit()->text());
|
m_oauth->setClientId(m_ui.m_txtAppId->lineEdit()->text());
|
||||||
m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text());
|
m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text());
|
||||||
m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text());
|
||||||
|
|
|
@ -135,6 +135,10 @@ void GmailNetworkFactory::initializeOauth() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GmailNetworkFactory::setOauth(OAuth2Service* oauth) {
|
||||||
|
m_oauth2 = oauth;
|
||||||
|
}
|
||||||
|
|
||||||
void GmailNetworkFactory::setUsername(const QString& username) {
|
void GmailNetworkFactory::setUsername(const QString& username) {
|
||||||
m_username = username;
|
m_username = username;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class GmailNetworkFactory : public QObject {
|
||||||
void setService(GmailServiceRoot* service);
|
void setService(GmailServiceRoot* service);
|
||||||
|
|
||||||
OAuth2Service* oauth() const;
|
OAuth2Service* oauth() const;
|
||||||
|
void setOauth(OAuth2Service* oauth);
|
||||||
|
|
||||||
QString username() const;
|
QString username() const;
|
||||||
void setUsername(const QString& username);
|
void setUsername(const QString& username);
|
||||||
|
@ -62,8 +63,6 @@ class GmailNetworkFactory : public QObject {
|
||||||
const QNetworkProxy& custom_proxy);
|
const QNetworkProxy& custom_proxy);
|
||||||
QList<Message> decodeLiteMessages(const QString& messages_json_data, const QString& stream_id, QString& next_page_token);
|
QList<Message> decodeLiteMessages(const QString& messages_json_data, const QString& stream_id, QString& next_page_token);
|
||||||
|
|
||||||
//RootItem* decodeFeedCategoriesData(const QString& categories);
|
|
||||||
|
|
||||||
void initializeOauth();
|
void initializeOauth();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -24,9 +24,13 @@ void FormEditInoreaderAccount::apply() {
|
||||||
bool editing_account = !applyInternal<InoreaderServiceRoot>();
|
bool editing_account = !applyInternal<InoreaderServiceRoot>();
|
||||||
|
|
||||||
if (!editing_account) {
|
if (!editing_account) {
|
||||||
// We are creating new account.
|
// We transfer refresh token to avoid the need to login once more,
|
||||||
m_details->m_oauth->setParent(account<InoreaderServiceRoot>()->network());
|
// then we delete testing OAuth service.
|
||||||
account<InoreaderServiceRoot>()->network()->setOauth(m_details->m_oauth);
|
account<InoreaderServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
|
||||||
|
account<InoreaderServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
|
||||||
|
account<InoreaderServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
|
||||||
|
m_details->m_oauth->logout();
|
||||||
|
m_details->m_oauth->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
account<InoreaderServiceRoot>()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text());
|
account<InoreaderServiceRoot>()->network()->oauth()->setClientId(m_details->m_ui.m_txtAppId->lineEdit()->text());
|
||||||
|
@ -49,8 +53,7 @@ void FormEditInoreaderAccount::setEditableAccount(ServiceRoot* editable_account)
|
||||||
FormAccountDetails::setEditableAccount(editable_account);
|
FormAccountDetails::setEditableAccount(editable_account);
|
||||||
|
|
||||||
if (m_details->m_oauth != nullptr) {
|
if (m_details->m_oauth != nullptr) {
|
||||||
// Remove OAuth meant for new account.
|
// We will use live OAuth service for testing.
|
||||||
// We are load existing account and we will use its OAuth.
|
|
||||||
m_details->m_oauth->logout();
|
m_details->m_oauth->logout();
|
||||||
m_details->m_oauth->deleteLater();
|
m_details->m_oauth->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ InoreaderAccountDetails::InoreaderAccountDetails(QWidget* parent)
|
||||||
m_ui.m_spinLimitMessages->setMinimum(INOREADER_MIN_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setMinimum(INOREADER_MIN_BATCH_SIZE);
|
||||||
m_ui.m_spinLimitMessages->setMaximum(INOREADER_MAX_BATCH_SIZE);
|
m_ui.m_spinLimitMessages->setMaximum(INOREADER_MAX_BATCH_SIZE);
|
||||||
|
|
||||||
checkUsername(m_ui.m_txtUsername->lineEdit()->text());
|
emit m_ui.m_txtUsername->lineEdit()->textChanged(m_ui.m_txtUsername->lineEdit()->text());
|
||||||
|
|
||||||
m_ui.m_txtAppId->lineEdit()->setText(INOREADER_OAUTH_CLI_ID);
|
m_ui.m_txtAppId->lineEdit()->setText(INOREADER_OAUTH_CLI_ID);
|
||||||
m_ui.m_txtAppKey->lineEdit()->setText(INOREADER_OAUTH_CLI_KEY);
|
m_ui.m_txtAppKey->lineEdit()->setText(INOREADER_OAUTH_CLI_KEY);
|
||||||
|
|
|
@ -31,6 +31,9 @@ class InoreaderAccountDetails : public QWidget {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::InoreaderAccountDetails m_ui;
|
Ui::InoreaderAccountDetails m_ui;
|
||||||
|
|
||||||
|
// Testing OAuth service. Only for testing. Resulting tokens
|
||||||
|
//
|
||||||
OAuth2Service* m_oauth;
|
OAuth2Service* m_oauth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue