gmail bundled tokens PoC

This commit is contained in:
Martin Rotter 2021-02-25 10:54:31 +01:00
parent 8f2fa52ee9
commit 1d5b69b366
3 changed files with 48 additions and 1 deletions

View file

@ -2798,8 +2798,24 @@ bool DatabaseQueries::overwriteGmailAccount(const QSqlDatabase& db, const QStrin
"redirect_url = :redirect_url, refresh_token = :refresh_token , msg_limit = :msg_limit " "redirect_url = :redirect_url, refresh_token = :refresh_token , msg_limit = :msg_limit "
"WHERE id = :id;"); "WHERE id = :id;");
query.bindValue(QSL(":username"), username); query.bindValue(QSL(":username"), username);
#if defined(GMAIL_OFFICIAL_SUPPORT)
const QString official_app_id = TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY);
const QString official_app_key = TextFactory::decrypt(GMAIL_CLIENT_SECRET, OAUTH_DECRYPTION_KEY);
if (official_app_id == app_id) {
query.bindValue(QSL(":app_id"), {});
query.bindValue(QSL(":app_key"), {});
}
else {
query.bindValue(QSL(":app_id"), app_id); query.bindValue(QSL(":app_id"), app_id);
query.bindValue(QSL(":app_key"), app_key); query.bindValue(QSL(":app_key"), app_key);
}
#else
query.bindValue(QSL(":app_id"), app_id);
query.bindValue(QSL(":app_key"), app_key);
#endif
query.bindValue(QSL(":redirect_url"), redirect_url); query.bindValue(QSL(":redirect_url"), redirect_url);
query.bindValue(QSL(":refresh_token"), refresh_token); query.bindValue(QSL(":refresh_token"), refresh_token);
query.bindValue(QSL(":id"), account_id); query.bindValue(QSL(":id"), account_id);
@ -2826,8 +2842,24 @@ bool DatabaseQueries::createGmailAccount(const QSqlDatabase& db, int id_to_assig
"VALUES (:id, :username, :app_id, :app_key, :redirect_url, :refresh_token, :msg_limit);"); "VALUES (:id, :username, :app_id, :app_key, :redirect_url, :refresh_token, :msg_limit);");
q.bindValue(QSL(":id"), id_to_assign); q.bindValue(QSL(":id"), id_to_assign);
q.bindValue(QSL(":username"), username); q.bindValue(QSL(":username"), username);
#if defined(GMAIL_OFFICIAL_SUPPORT)
const QString official_app_id = TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY);
const QString official_app_key = TextFactory::decrypt(GMAIL_CLIENT_SECRET, OAUTH_DECRYPTION_KEY);
if (official_app_id == app_id) {
q.bindValue(QSL(":app_id"), {});
q.bindValue(QSL(":app_key"), {});
}
else {
q.bindValue(QSL(":app_id"), app_id); q.bindValue(QSL(":app_id"), app_id);
q.bindValue(QSL(":app_key"), app_key); q.bindValue(QSL(":app_key"), app_key);
}
#else
q.bindValue(QSL(":app_id"), app_id);
q.bindValue(QSL(":app_key"), app_key);
#endif
q.bindValue(QSL(":redirect_url"), redirect_url); q.bindValue(QSL(":redirect_url"), redirect_url);
q.bindValue(QSL(":refresh_token"), refresh_token); q.bindValue(QSL(":refresh_token"), refresh_token);
q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GMAIL_DEFAULT_BATCH_SIZE : batch_size); q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? GMAIL_DEFAULT_BATCH_SIZE : batch_size);

View file

@ -32,8 +32,23 @@ void FormEditGmailAccount::apply() {
m_details->m_oauth->deleteLater(); m_details->m_oauth->deleteLater();
} }
#if defined(GMAIL_OFFICIAL_SUPPORT)
if (m_details->m_ui.m_txtAppId->lineEdit()->text().isEmpty() ||
m_details->m_ui.m_txtAppKey->lineEdit()->text().isEmpty()) {
account<GmailServiceRoot>()->network()->oauth()->setClientId(TextFactory::decrypt(GMAIL_CLIENT_ID,
OAUTH_DECRYPTION_KEY));
account<GmailServiceRoot>()->network()->oauth()->setClientSecret(TextFactory::decrypt(GMAIL_CLIENT_SECRET,
OAUTH_DECRYPTION_KEY));
}
else {
#endif
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());
#if defined(GMAIL_OFFICIAL_SUPPORT)
}
#endif
account<GmailServiceRoot>()->network()->oauth()->setRedirectUrl(m_details->m_ui.m_txtRedirectUrl->lineEdit()->text()); account<GmailServiceRoot>()->network()->oauth()->setRedirectUrl(m_details->m_ui.m_txtRedirectUrl->lineEdit()->text());
account<GmailServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text()); account<GmailServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());

View file

@ -66,7 +66,7 @@ void GmailAccountDetails::testSetup() {
#if defined(GMAIL_OFFICIAL_SUPPORT) #if defined(GMAIL_OFFICIAL_SUPPORT)
if (m_ui.m_txtAppId->lineEdit()->text().isEmpty() || m_ui.m_txtAppKey->lineEdit()->text().isEmpty()) { if (m_ui.m_txtAppId->lineEdit()->text().isEmpty() || m_ui.m_txtAppKey->lineEdit()->text().isEmpty()) {
m_oauth->setClientId(TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY)); m_oauth->setClientId(TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY));
m_oauth->setClientSecret(TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY)); m_oauth->setClientSecret(TextFactory::decrypt(GMAIL_CLIENT_SECRET, OAUTH_DECRYPTION_KEY));
} }
else { else {
#endif #endif