mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kutils: implement login via OAuth access token
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f79e175d56
commit
a4ec0f5724
6 changed files with 62 additions and 6 deletions
|
@ -71,6 +71,7 @@ public:
|
|||
KEMail::KEMailSSLType m_ssl;
|
||||
QString m_user;
|
||||
QString m_password;
|
||||
QString m_oauth;
|
||||
QString m_from;
|
||||
QByteArray m_data;
|
||||
QString m_errorstring;
|
||||
|
@ -237,6 +238,22 @@ bool KEMail::setPassword(const QString &password)
|
|||
return true;
|
||||
}
|
||||
|
||||
QString KEMail::oauth() const
|
||||
{
|
||||
return d->m_oauth;
|
||||
}
|
||||
|
||||
bool KEMail::setOAuth(const QString &oauth)
|
||||
{
|
||||
d->m_errorstring.clear();
|
||||
if (oauth.isEmpty()) {
|
||||
d->m_errorstring = i18n("Invalid OAuth access token: %1", oauth);
|
||||
return false;
|
||||
}
|
||||
d->m_oauth = oauth;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString KEMail::from() const
|
||||
{
|
||||
return d->m_from;
|
||||
|
@ -282,6 +299,7 @@ bool KEMail::send(const QStringList &to, const QString &subject, const QString &
|
|||
const QByteArray serverbytes = d->m_server.url().toAscii();
|
||||
const QByteArray userbytes = d->m_user.toAscii();
|
||||
const QByteArray passwordbytes = d->m_password.toAscii();
|
||||
const QByteArray oauthbytes = d->m_oauth.toAscii();
|
||||
const QByteArray frombytes = d->m_from.toAscii();
|
||||
|
||||
CURLcode curlresult = curl_easy_setopt(d->m_curl, CURLOPT_URL, serverbytes.constData());
|
||||
|
@ -333,9 +351,17 @@ bool KEMail::send(const QStringList &to, const QString &subject, const QString &
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: XOAUTH2 option and add setting to KEMailSettings
|
||||
// (void)curl_easy_setopt(d->m_curl, CURLOPT_XOAUTH2_BEARER, "");
|
||||
curlresult = curl_easy_setopt(d->m_curl, CURLOPT_LOGIN_OPTIONS, "AUTH=PLAIN");
|
||||
curlresult = curl_easy_setopt(d->m_curl, CURLOPT_XOAUTH2_BEARER, oauthbytes.constData());
|
||||
if (curlresult != CURLE_OK) {
|
||||
d->m_errorstring = curl_easy_strerror(curlresult);
|
||||
kWarning() << d->m_errorstring;
|
||||
curl_easy_cleanup(d->m_curl);
|
||||
d->m_curl = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// PLAIN, LOGIN, OAUTHBEARER, XOAUTH2
|
||||
curlresult = curl_easy_setopt(d->m_curl, CURLOPT_LOGIN_OPTIONS, "AUTH=*");
|
||||
if (curlresult != CURLE_OK) {
|
||||
d->m_errorstring = curl_easy_strerror(curlresult);
|
||||
kWarning() << d->m_errorstring;
|
||||
|
|
|
@ -77,6 +77,8 @@ public:
|
|||
bool setUser(const QString &user);
|
||||
QString password() const;
|
||||
bool setPassword(const QString &password);
|
||||
QString oauth() const;
|
||||
bool setOAuth(const QString &oauth);
|
||||
|
||||
QString from() const;
|
||||
bool setFrom(const QString &from);
|
||||
|
|
|
@ -92,6 +92,7 @@ KEMailDialog::KEMailDialog(QWidget *parent, Qt::WindowFlags flags)
|
|||
d->ui.setupUi(mainWidget());
|
||||
d->ui.userlineedit->setText(d->kemail->user());
|
||||
d->ui.passlineedit->setText(d->kemail->password());
|
||||
d->ui.oauthlineedit->setText(d->kemail->oauth());
|
||||
connect(d->ui.settingslabel, SIGNAL(leftClickedUrl()), this, SLOT(_slotSettings()));
|
||||
|
||||
connect(d, SIGNAL(sent()), this, SLOT(_slotSent()));
|
||||
|
@ -180,6 +181,7 @@ void KEMailDialog::showEvent(QShowEvent *event)
|
|||
// the password dialog is interactable via mouse
|
||||
const bool isuserempty = d->ui.userlineedit->text().isEmpty();
|
||||
const bool ispassempty = d->ui.passlineedit->text().isEmpty();
|
||||
const bool isoauthempty = d->ui.oauthlineedit->text().isEmpty();
|
||||
KEMailSettings* kemailsettings = nullptr;
|
||||
if (isuserempty || ispassempty) {
|
||||
kemailsettings = new KEMailSettings();
|
||||
|
@ -190,6 +192,9 @@ void KEMailDialog::showEvent(QShowEvent *event)
|
|||
if (ispassempty) {
|
||||
d->ui.passlineedit->setText(kemailsettings->getSetting(KEMailSettings::OutServerPass));
|
||||
}
|
||||
if (isoauthempty) {
|
||||
d->ui.oauthlineedit->setText(kemailsettings->getSetting(KEMailSettings::OutServerOAuth));
|
||||
}
|
||||
delete kemailsettings;
|
||||
}
|
||||
|
||||
|
@ -198,6 +203,7 @@ void KEMailDialog::slotButtonClicked(int button)
|
|||
if (button == KDialog::Ok) {
|
||||
d->kemail->setUser(d->ui.userlineedit->text());
|
||||
d->kemail->setPassword(d->ui.passlineedit->text());
|
||||
d->kemail->setOAuth(d->ui.oauthlineedit->text());
|
||||
if (!d->kemail->server().isValid()) {
|
||||
KMessageBox::error(this, i18n("No server specified"));
|
||||
return;
|
||||
|
@ -263,6 +269,7 @@ void KEMailDialog::_slotFinished()
|
|||
KEMailSettings kemailsettings;
|
||||
kemailsettings.setSetting(KEMailSettings::OutServerLogin, d->ui.userlineedit->text());
|
||||
kemailsettings.setSetting(KEMailSettings::OutServerPass, d->ui.passlineedit->text());
|
||||
kemailsettings.setSetting(KEMailSettings::OutServerOAuth, d->ui.oauthlineedit->text());
|
||||
}
|
||||
|
||||
#include "kemaildialog.moc"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>KPasswdRouletteDialogUI</string>
|
||||
<string>KEMailDialogUI</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
|
@ -49,6 +49,19 @@
|
|||
<string>Authentication</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="1">
|
||||
<widget class="KLineEdit" name="oauthlineedit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>OAuth access token:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
|
@ -66,7 +79,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<item row="3" column="0" colspan="3">
|
||||
<widget class="KUrlLabel" name="settingslabel">
|
||||
<property name="text">
|
||||
<string>Settings</string>
|
||||
|
|
|
@ -89,6 +89,9 @@ QString KEMailSettings::getSetting(KEMailSettings::Setting setting) const
|
|||
case OutServerPass: {
|
||||
return d->m_store->getPasswd(KPasswdStore::makeKey("OutgoingPassword"));
|
||||
}
|
||||
case OutServerOAuth: {
|
||||
return d->m_store->getPasswd(KPasswdStore::makeKey("OutgoingOAuth"));
|
||||
}
|
||||
};
|
||||
return QString();
|
||||
}
|
||||
|
@ -132,6 +135,10 @@ void KEMailSettings::setSetting(KEMailSettings::Setting setting, const QString &
|
|||
d->m_store->storePasswd(KPasswdStore::makeKey("OutgoingPassword"), value);
|
||||
break;
|
||||
}
|
||||
case OutServerOAuth: {
|
||||
d->m_store->storePasswd(KPasswdStore::makeKey("OutgoingOAuth"), value);
|
||||
break;
|
||||
}
|
||||
};
|
||||
cg.sync();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,8 @@ public:
|
|||
OutServer,
|
||||
OutServerSSL,
|
||||
OutServerLogin,
|
||||
OutServerPass
|
||||
OutServerPass,
|
||||
OutServerOAuth
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue