[SCM] ktp-auth-handler packaging branch, master, updated. debian/15.12.1-2-282-g080758e

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 23:59:37 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-auth-handler.git;a=commitdiff;h=2460e8e

The following commit has been merged in the master branch:
commit 2460e8e216e5f270598a78a788aa0e92ab7a37df
Author: Martin Klapetek <mklapetek at kde.org>
Date:   Tue Nov 11 20:53:21 2014 +0100

    Port auth handler SASL operation from KWallet to Accounts SSO
    
    REVIEW: 119955
---
 CMakeLists.txt                          |  35 ++++-------
 cmake/modules/FindKAccounts.cmake       |  27 ++++++++
 getcredentialsjob.cpp                   | 106 --------------------------------
 getcredentialsjob.h                     |  61 ------------------
 kssl/ksslinfodialog.h                   |   2 +-
 sasl-auth-op.cpp                        |  85 +++++--------------------
 sasl-auth-op.h                          |  13 +---
 tls-cert-verifier-op.cpp                |   2 +-
 x-telepathy-password-auth-operation.cpp |  86 +++++++++++++++++++-------
 x-telepathy-password-auth-operation.h   |  10 +--
 x-telepathy-password-prompt.cpp         |  11 +---
 x-telepathy-password-prompt.h           |   2 +-
 x-telepathy-sso-facebook-operation.cpp  |  30 ++++-----
 x-telepathy-sso-facebook-operation.h    |   4 +-
 x-telepathy-sso-google-operation.cpp    |  25 +++++---
 x-telepathy-sso-google-operation.h      |   4 +-
 16 files changed, 165 insertions(+), 338 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index abb08a7..8702818 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@ find_package (KTp REQUIRED)
 find_package (Qca REQUIRED)
 find_package(AccountsQt5 1.10 REQUIRED CONFIG)
 find_package(SignOnQt5 8.55 REQUIRED CONFIG)
+find_package(KAccounts REQUIRED)
 
 # include (MacroLibrary)
 #
@@ -39,7 +40,11 @@ include(ECMMarkNonGuiExecutable)
 include(CMakePackageConfigHelpers)
 include(FeatureSummary)
 
-include_directories ( ${QCA_INCLUDE_DIR} )
+include_directories (${QCA_INCLUDE_DIR}
+                     ${ACCOUNTSQT_INCLUDE_DIRS}
+                     ${SIGNONQT_INCLUDE_DIRS}
+                     ${KACCOUNTS_INCLUDE_DIRS}
+)
 
 feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
 
@@ -52,6 +57,8 @@ set(ktp_auth_handler_SRCS
     types.cpp
     x-telepathy-password-auth-operation.cpp
     x-telepathy-password-prompt.cpp
+    x-telepathy-sso-facebook-operation.cpp
+    x-telepathy-sso-google-operation.cpp
     x-messenger-oauth2-auth-operation.cpp
     x-messenger-oauth2-prompt.cpp
     conference-auth-op.cpp
@@ -61,6 +68,9 @@ set(ktp_auth_handler_SRCS
 set(ktp_auth_handler_LIBS
     KTp::CommonInternals
     ${Qca_LIBRARY}
+    ${ACCOUNTSQT_LIBRARIES}
+    ${SIGNONQT_LIBRARIES}
+    ${KACCOUNTS_LIBRARIES}
     KF5::WidgetsAddons
     KF5::Wallet
     KF5::I18n
@@ -73,29 +83,6 @@ set(ktp_auth_handler_LIBS
     Qt5::Network
 )
 
-#If we find Accounts-SSO frameworks, add support for it
-if(AccountsQt5_FOUND AND SignOnQt5_FOUND)
-
-    add_definitions(-DHAVE_SSO)
-    set(ktp_auth_handler_SRCS
-        ${ktp_auth_handler_SRCS}
-        x-telepathy-sso-facebook-operation.cpp
-        x-telepathy-sso-google-operation.cpp
-        getcredentialsjob.cpp
-    )
-
-    set(ktp_auth_handler_LIBS
-        ${ktp_auth_handler_LIBS}
-        ${ACCOUNTSQT_LIBRARIES}
-        ${SIGNONQT_LIBRARIES}
-    )
-
-    include_directories(${ACCOUNTSQT_INCLUDE_DIRS}
-                        ${SIGNONQT_INCLUDE_DIRS}
-    )
-
-endif(AccountsQt5_FOUND AND SignOnQt5_FOUND)
-
 configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
 
 ki18n_wrap_ui(ktp_auth_handler_SRCS x-telepathy-password-prompt.ui)
diff --git a/cmake/modules/FindKAccounts.cmake b/cmake/modules/FindKAccounts.cmake
new file mode 100644
index 0000000..ad12c01
--- /dev/null
+++ b/cmake/modules/FindKAccounts.cmake
@@ -0,0 +1,27 @@
+# Try to find the KAccounts UI library
+#
+# Copyright (c) 2011, Dario Freddi <drf at kde.org>
+# Copyright (c) 2014, Martin Klapetek <mklapetek at kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+SET (KACCOUNTS_FIND_REQUIRED ${KAccounts_FIND_REQUIRED})
+if (KACCOUNTS_INCLUDE_DIRS AND KACCOUNTS_LIBRARIES)
+  # Already in cache, be silent
+  set(KACCOUNTS_FIND_QUIETLY TRUE)
+endif (KACCOUNTS_INCLUDE_DIRS AND KACCOUNTS_LIBRARIES)
+
+find_path(KACCOUNTS_INCLUDE_DIRS
+  NAMES KAccounts/kaccountsuiplugin.h
+  PATHS ${KF5_INCLUDE_DIR}
+)
+
+find_library(KACCOUNTS_LIBRARIES NAMES kaccounts)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(KAccounts DEFAULT_MSG
+                                  KACCOUNTS_LIBRARIES
+                                  KACCOUNTS_INCLUDE_DIRS)
+
+mark_as_advanced(KACCOUNTS_INCLUDE_DIRS KACCOUNTS_LIBRARIES)
diff --git a/getcredentialsjob.cpp b/getcredentialsjob.cpp
deleted file mode 100644
index 7016ede..0000000
--- a/getcredentialsjob.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*************************************************************************************
- *  Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas at kde.org>              *
- *                                                                                   *
- *  This library is free software; you can redistribute it and/or                    *
- *  modify it under the terms of the GNU Lesser General Public                       *
- *  License as published by the Free Software Foundation; either                     *
- *  version 2 of the License, or (at your option) any later version.                 *
- *                                                                                   *
- *  This library is distributed in the hope that it will be useful,                  *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                *
- *  Library General Public License for more details.                                 *
- *                                                                                   *
- *  You should have received a copy of the GNU Library General Public License        *
- *  along with this library; see the file COPYING.LIB.  If not, write to             *
- *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,             *
- *  Boston, MA 02110-1301, USA.                                                      *
- *************************************************************************************/
-
-#include "getcredentialsjob.h"
-
-#include <Accounts/Manager>
-#include <Accounts/Account>
-#include <Accounts/AccountService>
-
-#include <SignOn/Identity>
-
-#include <QDebug>
-
-GetCredentialsJob::GetCredentialsJob(const Accounts::AccountId& id, QObject* parent)
-: KJob(parent)
-, m_id(id)
-, m_manager(new Accounts::Manager(this))
-{
-
-}
-
-void GetCredentialsJob::start()
-{
-    QMetaObject::invokeMethod(this, "getCredentials", Qt::QueuedConnection);
-}
-
-void GetCredentialsJob::setServiceType(const QString& serviceType)
-{
-    m_serviceType = serviceType;
-}
-
-void GetCredentialsJob::getCredentials()
-{
-    Accounts::Account *acc = m_manager->account(m_id);
-    if (!acc) {
-        setError(-1);
-        setErrorText("Could not find account");
-        emitResult();
-        return;
-    }
-    Accounts::AccountService *service = new Accounts::AccountService(acc, m_manager->service(m_serviceType), this);
-
-    Accounts::AuthData authData = service->authData();
-    m_authData = authData.parameters();
-    SignOn::Identity* identity = SignOn::Identity::existingIdentity(authData.credentialsId(), this);
-
-    if (!identity) {
-        setError(-1);
-        setErrorText("Could not find credentials");
-        emitResult();
-        return;
-    }
-
-    m_authData["AccountUsername"] = acc->value("username").toString();
-    QPointer<SignOn::AuthSession> authSession = identity->createSession(authData.method());
-
-    connect(authSession, SIGNAL(response(SignOn::SessionData)),
-            SLOT(sessionResponse(SignOn::SessionData)));
-    connect(authSession, SIGNAL(error(SignOn::Error)),
-            SLOT(sessionError(SignOn::Error)));
-
-    qDebug() << authData.parameters();
-    qDebug() << authData.mechanism();
-    authSession->process(authData.parameters(), authData.mechanism());
-}
-
-void GetCredentialsJob::sessionResponse(const SignOn::SessionData& data)
-{
-    qDebug() << data.toMap();
-    m_sessionData = data;
-    emitResult();
-}
-
-void GetCredentialsJob::sessionError(const SignOn::Error& error)
-{
-    qDebug() << error.message();
-    setError(-1);
-    setErrorText(error.message());
-    emitResult();
-}
-
-Accounts::AccountId GetCredentialsJob::accountId() const
-{
-    return m_id;
-}
-
-QVariantMap GetCredentialsJob::credentialsData() const
-{
-    return m_sessionData.toMap().unite(m_authData);
-}
diff --git a/getcredentialsjob.h b/getcredentialsjob.h
deleted file mode 100644
index 0981115..0000000
--- a/getcredentialsjob.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*************************************************************************************
- *  Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas at kde.org>              *
- *                                                                                   *
- *  This library is free software; you can redistribute it and/or                    *
- *  modify it under the terms of the GNU Lesser General Public                       *
- *  License as published by the Free Software Foundation; either                     *
- *  version 2 of the License, or (at your option) any later version.                 *
- *                                                                                   *
- *  This library is distributed in the hope that it will be useful,                  *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                *
- *  Library General Public License for more details.                                 *
- *                                                                                   *
- *  You should have received a copy of the GNU Library General Public License        *
- *  along with this library; see the file COPYING.LIB.  If not, write to             *
- *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,             *
- *  Boston, MA 02110-1301, USA.                                                      *
- *************************************************************************************/
-
-#ifndef GET_CREDENTIALS_JOB_H
-#define GET_CREDENTIALS_JOB_H
-
-#include <kjob.h>
-
-#include <Accounts/Account>
-#include <Accounts/AuthData>
-#include <SignOn/SessionData>
-
-namespace Accounts {
-    class Manager;
-};
-namespace SignOn {
-    class Error;
-};
-
-class GetCredentialsJob : public KJob
-{
-    Q_OBJECT
-public:
-    explicit GetCredentialsJob(const Accounts::AccountId &id, QObject* parent = 0);
-    virtual void start();
-
-    void setServiceType(const QString &serviceType);
-
-    QVariantMap credentialsData() const;
-    Accounts::AccountId accountId() const;
-
-private Q_SLOTS:
-    void getCredentials();
-    void sessionResponse(const SignOn::SessionData &data);
-    void sessionError(const SignOn::Error &error);
-
-private:
-    QString m_serviceType;
-    Accounts::AccountId m_id;
-    QVariantMap m_authData;
-    Accounts::Manager *m_manager;
-    SignOn::SessionData m_sessionData;
-};
-
-#endif //GET_CREDENTIALS_JOB_H
diff --git a/kssl/ksslinfodialog.h b/kssl/ksslinfodialog.h
index b65c225..ba994bb 100644
--- a/kssl/ksslinfodialog.h
+++ b/kssl/ksslinfodialog.h
@@ -40,7 +40,7 @@
  * @see KSSL
  * @short KDE SSL Information Dialog
  */
-class KIO_EXPORT KSslInfoDialog : public KDialog {
+class KIO_EXPORT KSslInfoDialog : public QDialog {
 	Q_OBJECT
 public:
 	/**
diff --git a/sasl-auth-op.cpp b/sasl-auth-op.cpp
index c54d662..1b251e0 100644
--- a/sasl-auth-op.cpp
+++ b/sasl-auth-op.cpp
@@ -22,11 +22,8 @@
 
 #include "x-telepathy-password-auth-operation.h"
 #include "x-messenger-oauth2-auth-operation.h"
-
-#ifdef HAVE_SSO
-    #include "x-telepathy-sso-facebook-operation.h"
-    #include "x-telepathy-sso-google-operation.h"
-#endif
+#include "x-telepathy-sso-facebook-operation.h"
+#include "x-telepathy-sso-google-operation.h"
 
 #include <QtCore/QScopedPointer>
 
@@ -35,23 +32,18 @@
 #include <QDebug>
 #include <KLocalizedString>
 
-#include <KTp/wallet-interface.h>
-#include <KTp/pending-wallet.h>
-
 SaslAuthOp::SaslAuthOp(const Tp::AccountPtr &account,
         const Tp::ChannelPtr &channel)
     : Tp::PendingOperation(channel),
-      m_walletInterface(0),
       m_account(account),
       m_channel(channel),
       m_saslIface(channel->interface<Tp::Client::ChannelInterfaceSASLAuthenticationInterface>())
 {
-#ifdef HAVE_SSO
-    m_accountStorageId = 0;
-#endif
+    KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kaccounts-ktprc"));
+    KConfigGroup ktpKaccountsGroup = config->group(QStringLiteral("ktp-kaccounts"));
+    m_kaccountsId = ktpKaccountsGroup.readEntry(account->objectPath()).toUInt();
 
-    //FIXME: We should open the wallet only when required (not required for X-FACEBOOK-PLATFORM)
-    connect(KTp::WalletInterface::openWallet(), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onOpenWalletOperationFinished(Tp::PendingOperation*)));
+    setReady();
 }
 
 SaslAuthOp::~SaslAuthOp()
@@ -76,35 +68,26 @@ void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
     QString error = qdbus_cast<QString>(props.value(QLatin1String("SASLError")));
     QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value(QLatin1String("SASLErrorDetails")));
 
-#ifdef HAVE_SSO
-    if (mechanisms.contains(QLatin1String("X-FACEBOOK-PLATFORM")) && m_accountStorageId) {
-        XTelepathySSOFacebookOperation *authop = new XTelepathySSOFacebookOperation(m_account, m_accountStorageId, m_saslIface);
+    if (mechanisms.contains(QLatin1String("X-FACEBOOK-PLATFORM")) && m_kaccountsId != 0) {
+        qDebug() << "Starting Facebook OAuth auth";
+        XTelepathySSOFacebookOperation *authop = new XTelepathySSOFacebookOperation(m_account, m_kaccountsId, m_saslIface);
         connect(authop,
                 SIGNAL(finished(Tp::PendingOperation*)),
                 SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
 
         authop->onSASLStatusChanged(status, error, errorDetails);
-    }
-    else if(mechanisms.contains(QLatin1String("X-OAUTH2")) && m_accountStorageId) {
-        XTelepathySSOGoogleOperation *authop = new XTelepathySSOGoogleOperation(m_account, m_accountStorageId, m_saslIface);
+    } else if (mechanisms.contains(QLatin1String("X-OAUTH2")) && m_kaccountsId != 0) {
+        qDebug() << "Starting X-OAuth2 auth";
+        XTelepathySSOGoogleOperation *authop = new XTelepathySSOGoogleOperation(m_account, m_kaccountsId, m_saslIface);
         connect(authop,
                 SIGNAL(finished(Tp::PendingOperation*)),
                 SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
 
         authop->onSASLStatusChanged(status, error, errorDetails);
-    } else //if...
-#endif
-    if (mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
+    } else if (mechanisms.contains(QLatin1String("X-TELEPATHY-PASSWORD"))) {
+        qDebug() << "Starting Password auth";
         Q_EMIT ready(this);
-        XTelepathyPasswordAuthOperation *authop = new XTelepathyPasswordAuthOperation(m_account, m_saslIface, m_walletInterface, qdbus_cast<bool>(props.value(QLatin1String("CanTryAgain"))));
-        connect(authop,
-                SIGNAL(finished(Tp::PendingOperation*)),
-                SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
-
-        authop->onSASLStatusChanged(status, error, errorDetails);
-    } else if (mechanisms.contains(QLatin1String("X-MESSENGER-OAUTH2"))) {
-        Q_EMIT ready(this);
-        XMessengerOAuth2AuthOperation *authop = new XMessengerOAuth2AuthOperation(m_account, m_saslIface, m_walletInterface);
+        XTelepathyPasswordAuthOperation *authop = new XTelepathyPasswordAuthOperation(m_account, m_saslIface, qdbus_cast<bool>(props.value(QLatin1String("CanTryAgain"))));
         connect(authop,
                 SIGNAL(finished(Tp::PendingOperation*)),
                 SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
@@ -119,20 +102,6 @@ void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
     }
 }
 
-void SaslAuthOp::onOpenWalletOperationFinished(Tp::PendingOperation *op)
-{
-    KTp::PendingWallet *walletOp = qobject_cast<KTp::PendingWallet*>(op);
-    Q_ASSERT(walletOp);
-
-    m_walletInterface = walletOp->walletInterface();
-
-#ifdef HAVE_SSO
-    fetchAccountStorage();
-#else
-    setReady();
-#endif
-}
-
 void SaslAuthOp::onAuthOperationFinished(Tp::PendingOperation *op)
 {
     m_channel->requestClose();
@@ -150,28 +119,4 @@ void SaslAuthOp::setReady()
             SLOT(gotProperties(Tp::PendingOperation*)));
 }
 
-#ifdef HAVE_SSO
-void SaslAuthOp::onGetAccountStorageFetched(Tp::PendingOperation* op)
-{
-    qDebug();
-    Tp::PendingVariantMap *pendingMap = qobject_cast<Tp::PendingVariantMap*>(op);
-
-    m_accountStorageId = pendingMap->result()["StorageIdentifier"].value<QDBusVariant>().variant().toInt();
-    qDebug() << m_accountStorageId;
-
-    setReady();
-}
-
-void SaslAuthOp::fetchAccountStorage()
-{
-    //Check if the account has any StorageIdentifier, in which case we will
-    //prioritize those mechanism related with KDE Accounts integration
-    QScopedPointer<Tp::Client::AccountInterfaceStorageInterface> accountStorageInterface(
-        new Tp::Client::AccountInterfaceStorageInterface(m_account->busName(), m_account->objectPath()));
-
-    Tp::PendingVariantMap *pendingMap = accountStorageInterface->requestAllProperties();
-    connect(pendingMap, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onGetAccountStorageFetched(Tp::PendingOperation*)));
-}
-#endif
-
 #include "sasl-auth-op.moc"
diff --git a/sasl-auth-op.h b/sasl-auth-op.h
index 9808019..182fe04 100644
--- a/sasl-auth-op.h
+++ b/sasl-auth-op.h
@@ -43,26 +43,15 @@ Q_SIGNALS:
 
 private Q_SLOTS:
     void gotProperties(Tp::PendingOperation *op);
-    void onOpenWalletOperationFinished(Tp::PendingOperation *op);
     void onAuthOperationFinished(Tp::PendingOperation *op);
 
-#ifdef HAVE_SSO
-    //FIXME this is a workaround until Tp::Client::AccountInterfaceStorageInterface is merged into Tp::Account
-    //https://bugs.freedesktop.org/show_bug.cgi?id=63191
-    void onGetAccountStorageFetched(Tp::PendingOperation *op);
-#endif
-
 private:
     void setReady();
     KTp::WalletInterface *m_walletInterface;
     Tp::AccountPtr m_account;
     Tp::ChannelPtr m_channel;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
-
-#ifdef HAVE_SSO
-    void fetchAccountStorage();
-    int m_accountStorageId;
-#endif
+    quint32 m_kaccountsId;
 };
 
 #endif // SASL_AUTH_OP_H
diff --git a/tls-cert-verifier-op.cpp b/tls-cert-verifier-op.cpp
index d319ddf..1f0bd61 100644
--- a/tls-cert-verifier-op.cpp
+++ b/tls-cert-verifier-op.cpp
@@ -93,7 +93,7 @@ void TlsCertVerifierOp::gotProperties(Tp::PendingOperation *op)
     // Initialize QCA module
     QCA::Initializer initializer;
 
-    if(!QCA::isSupported("cert")) {
+    if (!QCA::isSupported("cert")) {
       Tp::TLSCertificateRejectionList rejections;
       m_authTLSCertificateIface->Reject(rejections);
       m_channel->requestClose();
diff --git a/x-telepathy-password-auth-operation.cpp b/x-telepathy-password-auth-operation.cpp
index f999748..aceb6a2 100644
--- a/x-telepathy-password-auth-operation.cpp
+++ b/x-telepathy-password-auth-operation.cpp
@@ -3,6 +3,7 @@
  *   @author Andre Moreira Magalhaes <andre.magalhaes at collabora.co.uk>
  * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
  * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
+ * Copyright (C) 2014 Martin Klapetek <mklapetek at kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,25 +23,38 @@
 #include "x-telepathy-password-auth-operation.h"
 #include "x-telepathy-password-prompt.h"
 
+#include <KAccounts/getcredentialsjob.h>
+#include <KAccounts/core.h>
+
 #include <QDebug>
+
 #include <KLocalizedString>
+#include <KSharedConfig>
+#include <KConfigGroup>
 
-#include <KTp/wallet-interface.h>
+#include <Accounts/Account>
+#include <Accounts/Manager>
+#include <Accounts/AccountService>
+#include <SignOn/Identity>
 
 XTelepathyPasswordAuthOperation::XTelepathyPasswordAuthOperation(
         const Tp::AccountPtr &account,
         Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
-        KTp::WalletInterface *walletInterface,
         bool canTryAgain) :
     Tp::PendingOperation(account),
     m_account(account),
     m_saslIface(saslIface),
-    m_walletInterface(walletInterface),
     m_canTryAgain(canTryAgain)
 {
     connect(m_saslIface,
             SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
             SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
+
+    m_config = KSharedConfig::openConfig(QStringLiteral("kaccounts-ktprc"));
+    m_lastLoginFailedConfig = m_config->group(QStringLiteral("lastLoginFailed"));
+
+    KConfigGroup kaccountsGroup = m_config->group(QStringLiteral("ktp-kaccounts"));
+    m_kaccountsId = kaccountsGroup.readEntry(m_account->objectPath(), 0);
 }
 
 XTelepathyPasswordAuthOperation::~XTelepathyPasswordAuthOperation()
@@ -52,14 +66,25 @@ void XTelepathyPasswordAuthOperation::onSASLStatusChanged(uint status, const QSt
 {
     if (status == Tp::SASLStatusNotStarted) {
         qDebug() << "Requesting password";
-        promptUser(m_canTryAgain || !m_walletInterface->hasEntry(m_account, QLatin1String("lastLoginFailed")));
+        // if we have non-null id AND if the last attempt didn't fail,
+        // proceed with the credentials receieved from the SSO;
+        // otherwise prompt the user
+        if (m_kaccountsId != 0 && !m_lastLoginFailedConfig.hasKey(m_account->objectPath())) {
+            GetCredentialsJob *credentialsJob = new GetCredentialsJob(m_kaccountsId, this);
+            connect(credentialsJob, &GetCredentialsJob::finished, [this](KJob *job){
+                m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), qobject_cast<GetCredentialsJob*>(job)->credentialsData().value("Secret").toByteArray());
+            });
+            credentialsJob->start();
+        } else {
+            promptUser();
+        }
     } else if (status == Tp::SASLStatusServerSucceeded) {
         qDebug() << "Authentication handshake";
         m_saslIface->AcceptSASL();
     } else if (status == Tp::SASLStatusSucceeded) {
         qDebug() << "Authentication succeeded";
-        if (m_walletInterface->hasEntry(m_account, QLatin1String("lastLoginFailed"))) {
-            m_walletInterface->removeEntry(m_account, QLatin1String("lastLoginFailed"));
+        if (m_lastLoginFailedConfig.hasKey(m_account->objectPath())) {
+            m_lastLoginFailedConfig.deleteEntry(m_account->objectPath());
         }
         setFinished();
     } else if (status == Tp::SASLStatusInProgress) {
@@ -69,10 +94,11 @@ void XTelepathyPasswordAuthOperation::onSASLStatusChanged(uint status, const QSt
 
         if (m_canTryAgain) {
             qDebug() << "Retrying...";
-            promptUser(false);
+            promptUser();
         } else {
             qWarning() << "Authentication failed and cannot try again";
-            m_walletInterface->setEntry(m_account, QLatin1String("lastLoginFailed"), QLatin1String("true"));
+            m_lastLoginFailedConfig.writeEntry(m_account->objectPath(), "1");
+
             // We cannot try again, but we can request again to set the account
             // online. A new channel will be created, but since we set the
             // lastLoginFailed entry, next time we will prompt for password
@@ -86,18 +112,13 @@ void XTelepathyPasswordAuthOperation::onSASLStatusChanged(uint status, const QSt
     }
 }
 
-void XTelepathyPasswordAuthOperation::promptUser(bool isFirstRun)
+void XTelepathyPasswordAuthOperation::promptUser()
 {
-    if (m_walletInterface->hasPassword(m_account) && isFirstRun) {
-        m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"),
-                                            m_walletInterface->password(m_account).toUtf8());
-    } else {
-        m_dialog = new XTelepathyPasswordPrompt(m_account, m_walletInterface);
-        connect(m_dialog.data(),
-                SIGNAL(finished(int)),
-                SLOT(onDialogFinished(int)));
-        m_dialog.data()->show();
-    }
+    m_dialog = new XTelepathyPasswordPrompt(m_account);
+    connect(m_dialog.data(),
+            SIGNAL(finished(int)),
+            SLOT(onDialogFinished(int)));
+    m_dialog.data()->show();
 }
 
 void XTelepathyPasswordAuthOperation::onDialogFinished(int result)
@@ -115,11 +136,32 @@ void XTelepathyPasswordAuthOperation::onDialogFinished(int result)
         // save password in kwallet if necessary...
         if (!m_dialog.isNull()) {
             if (m_dialog.data()->savePassword()) {
-                qDebug() << "Saving password in wallet";
-                m_walletInterface->setPassword(m_account, m_dialog.data()->password());
+                qDebug() << "Saving password in SSO";
+                Accounts::Manager *manager = KAccounts::accountsManager();
+                Accounts::Account *acc = manager->account(m_kaccountsId);
+                if (acc) {
+                    Accounts::AccountService *service = new Accounts::AccountService(acc, manager->service(QString()), m_dialog);
+                    Accounts::AuthData authData = service->authData();
+                    SignOn::Identity *identity = SignOn::Identity::existingIdentity(authData.credentialsId(), m_dialog);
+
+                    // Get the current identity info, change the password and store it back
+                    connect(identity, &SignOn::Identity::info, [this, identity](SignOn::IdentityInfo info){
+                        info.setSecret(m_dialog->password());
+                        identity->storeCredentials(info);
+                        // we don't need the dialog anymore, delete it
+                        m_dialog.data()->deleteLater();
+                    });
+                    identity->queryInfo();
+                } else {
+                    // FIXME: Should this show a message box to the user? Or a notification?
+                    qWarning() << "Could not open Accounts Manager, password will not be stored";
+                    m_dialog.data()->deleteLater();
+                }
+            } else {
+                // The user does not want to save the password, delete the dialog
+                m_dialog.data()->deleteLater();
             }
             m_saslIface->StartMechanismWithData(QLatin1String("X-TELEPATHY-PASSWORD"), m_dialog.data()->password().toUtf8());
-            m_dialog.data()->deleteLater();
         }
     }
 }
diff --git a/x-telepathy-password-auth-operation.h b/x-telepathy-password-auth-operation.h
index 65d6462..540f9e3 100644
--- a/x-telepathy-password-auth-operation.h
+++ b/x-telepathy-password-auth-operation.h
@@ -23,7 +23,8 @@
 #include <TelepathyQt/Types>
 #include "x-telepathy-password-prompt.h"
 
-#include <KTp/wallet-interface.h>
+#include <KConfigGroup>
+#include <KSharedConfig>
 
 class XTelepathyPasswordAuthOperation : public Tp::PendingOperation
 {
@@ -34,7 +35,6 @@ public:
     explicit XTelepathyPasswordAuthOperation(
             const Tp::AccountPtr &account,
             Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
-            KTp::WalletInterface *walletInterface,
             bool canTryAgain);
     ~XTelepathyPasswordAuthOperation();
 
@@ -43,11 +43,13 @@ private Q_SLOTS:
     void onDialogFinished(int result);
 
 private:
-    void promptUser(bool isFirstPrompt);
+    void promptUser();
 
     Tp::AccountPtr m_account;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
-    KTp::WalletInterface *m_walletInterface;
+    KSharedConfigPtr m_config;
+    KConfigGroup m_lastLoginFailedConfig;
+    quint32 m_kaccountsId;
     bool m_canTryAgain;
     QPointer<XTelepathyPasswordPrompt> m_dialog;
 
diff --git a/x-telepathy-password-prompt.cpp b/x-telepathy-password-prompt.cpp
index b53b1f5..760ce6b 100644
--- a/x-telepathy-password-prompt.cpp
+++ b/x-telepathy-password-prompt.cpp
@@ -25,7 +25,7 @@
 #include <QDebug>
 #include <QtWidgets/QDialogButtonBox>
 
-XTelepathyPasswordPrompt::XTelepathyPasswordPrompt(const Tp::AccountPtr &account, KTp::WalletInterface *walletInterface, QWidget *parent)
+XTelepathyPasswordPrompt::XTelepathyPasswordPrompt(const Tp::AccountPtr &account, QWidget *parent)
     : QDialog(parent),
       ui(new Ui::XTelepathyPasswordPrompt)
 {
@@ -39,14 +39,7 @@ XTelepathyPasswordPrompt::XTelepathyPasswordPrompt(const Tp::AccountPtr &account
     ui->title->setPixmap(QIcon::fromTheme(account->iconName()).pixmap(22, 22));
     ui->passwordLineEdit->setFocus();
 
-    if (walletInterface->isOpen()) {
-        ui->savePassword->setChecked(true);
-        if (walletInterface->hasPassword(account)) {
-            ui->passwordLineEdit->setText(walletInterface->password(account));
-        }
-    } else {
-        ui->savePassword->setDisabled(true);
-    }
+    ui->savePassword->setEnabled(true);
 
     QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
     connect(dbb, SIGNAL(accepted()), this, SLOT(accept()));
diff --git a/x-telepathy-password-prompt.h b/x-telepathy-password-prompt.h
index fa8c1ce..9882bce 100644
--- a/x-telepathy-password-prompt.h
+++ b/x-telepathy-password-prompt.h
@@ -38,7 +38,7 @@ class XTelepathyPasswordPrompt : public QDialog
     Q_OBJECT
 
 public:
-    explicit XTelepathyPasswordPrompt(const Tp::AccountPtr &account, KTp::WalletInterface *walletInterface, QWidget *parent=0);
+    explicit XTelepathyPasswordPrompt(const Tp::AccountPtr &account, QWidget *parent=0);
     ~XTelepathyPasswordPrompt();
 
     QString password() const;
diff --git a/x-telepathy-sso-facebook-operation.cpp b/x-telepathy-sso-facebook-operation.cpp
index a4a9dc9..5b9bf57 100644
--- a/x-telepathy-sso-facebook-operation.cpp
+++ b/x-telepathy-sso-facebook-operation.cpp
@@ -1,5 +1,4 @@
 /*
-    <one line to give the program's name and a brief idea of what it does.>
     Copyright (C) 2013  David Edmundson <kde at davidedmundson.co.uk>
 
     This program is free software: you can redistribute it and/or modify
@@ -25,20 +24,20 @@
 #include <TelepathyQt/PendingVariantMap>
 
 #include <Accounts/Account>
+#include <KAccounts/getcredentialsjob.h>
 
 #include <QDebug>
 #include <QUrlQuery>
 #include <QUrl>
 
-#include "getcredentialsjob.h"
 
-XTelepathySSOFacebookOperation::XTelepathySSOFacebookOperation(const Tp::AccountPtr& account, int accountStorageId, Tp::Client::ChannelInterfaceSASLAuthenticationInterface* saslIface) :
-    PendingOperation(account),
-    m_account(account),
-    m_saslIface(saslIface),
-    m_accountStorageId(accountStorageId)
+XTelepathySSOFacebookOperation::XTelepathySSOFacebookOperation(const Tp::AccountPtr &account, quint32 kaccountsId, Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface)
+    : PendingOperation(account),
+      m_account(account),
+      m_saslIface(saslIface),
+      m_kaccountsId(kaccountsId)
 {
-    Q_ASSERT(m_accountStorageId);
+    Q_ASSERT(kaccountsId);
     connect(m_saslIface, SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)), SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
     connect(m_saslIface, SIGNAL(NewChallenge(QByteArray)), SLOT(onNewChallenge(QByteArray)));
 }
@@ -57,21 +56,24 @@ void XTelepathySSOFacebookOperation::onSASLStatusChanged(uint status, const QStr
         m_saslIface->StartMechanism(QLatin1String("X-FACEBOOK-PLATFORM"));
         break;
     }
+
     case Tp::SASLStatusServerSucceeded:
         qDebug() << "Authentication handshake";
         m_saslIface->AcceptSASL();
         break;
+
+    case Tp::SASLStatusSucceeded:
+        qDebug() << "Authentication succeeded";
+        setFinished();
+        break;
     }
 }
 
 void XTelepathySSOFacebookOperation::onNewChallenge(const QByteArray& challengeData)
 {
-    qDebug() << "New Challenge" << challengeData;
-
     m_challengeData = challengeData;
 
-    qDebug() << "GetCredentialsJob on account: " << m_accountStorageId;
-    GetCredentialsJob *job = new GetCredentialsJob(m_accountStorageId, this);
+    GetCredentialsJob *job = new GetCredentialsJob(m_kaccountsId, this);
     connect(job, SIGNAL(finished(KJob*)), SLOT(gotCredentials(KJob *)));
     job->start();
 }
@@ -96,7 +98,5 @@ void XTelepathySSOFacebookOperation::gotCredentials(KJob *kJob)
     fbResponseQuery.addQueryItem("call_id", "0");
     fbResponseQuery.addQueryItem("v", "1.0");
 
-    //.mid(1) trims leading '?' char
-    qDebug() << fbResponseQuery.query().mid(1);
-    m_saslIface->Respond(fbResponseQuery.query().mid(1).toUtf8());
+    m_saslIface->Respond(fbResponseQuery.query().toUtf8());
 }
diff --git a/x-telepathy-sso-facebook-operation.h b/x-telepathy-sso-facebook-operation.h
index 921ef2a..e924d4a 100644
--- a/x-telepathy-sso-facebook-operation.h
+++ b/x-telepathy-sso-facebook-operation.h
@@ -35,7 +35,7 @@ class XTelepathySSOFacebookOperation : public Tp::PendingOperation
 public:
     explicit XTelepathySSOFacebookOperation(
             const Tp::AccountPtr &account,
-            int accountStorageId,
+            quint32 kaccountsId,
             Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface);
 
 private Q_SLOTS:
@@ -47,7 +47,7 @@ private:
     Tp::AccountPtr m_account;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
 
-    int m_accountStorageId;
+    quint32 m_kaccountsId;
     QByteArray m_challengeData;
 
     friend class SaslAuthOp;
diff --git a/x-telepathy-sso-google-operation.cpp b/x-telepathy-sso-google-operation.cpp
index f678916..5656c07 100644
--- a/x-telepathy-sso-google-operation.cpp
+++ b/x-telepathy-sso-google-operation.cpp
@@ -17,27 +17,29 @@
  *  Boston, MA 02110-1301, USA.                                                      *
  *************************************************************************************/
 
-#include "getcredentialsjob.h"
 #include "x-telepathy-sso-google-operation.h"
 
+#include <KAccounts/getcredentialsjob.h>
 #include <QDebug>
 
-XTelepathySSOGoogleOperation::XTelepathySSOGoogleOperation(const Tp::AccountPtr& account, int accountStorageId, Tp::Client::ChannelInterfaceSASLAuthenticationInterface* saslIface)
+#include <KSharedConfig>
+#include <KConfigGroup>
+
+XTelepathySSOGoogleOperation::XTelepathySSOGoogleOperation(const Tp::AccountPtr &account, quint32 kaccountsId, Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface)
     : PendingOperation(account)
     , m_saslIface(saslIface)
-    , m_accountStorageId(accountStorageId)
+    , m_kaccountsId(kaccountsId)
 {
-    Q_ASSERT(m_accountStorageId);
     connect(m_saslIface, SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)), SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
 }
 
-void XTelepathySSOGoogleOperation::onSASLStatusChanged(uint status, const QString& reason, const QVariantMap& details)
+void XTelepathySSOGoogleOperation::onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details)
 {
     switch (status){
     case Tp::SASLStatusNotStarted:
     {
         qDebug() << "Status Not started";
-        GetCredentialsJob *job = new GetCredentialsJob(m_accountStorageId, this);
+        GetCredentialsJob *job = new GetCredentialsJob(m_kaccountsId, this);
         connect(job, SIGNAL(finished(KJob*)), SLOT(gotCredentials(KJob*)));
         job->start();
         break;
@@ -46,10 +48,15 @@ void XTelepathySSOGoogleOperation::onSASLStatusChanged(uint status, const QStrin
         qDebug() << "Status Server Succeeded";
         m_saslIface->AcceptSASL();
         break;
+
+    case Tp::SASLStatusSucceeded:
+        qDebug() << "Authentication succeeded";
+        setFinished();
+        break;
     }
 }
 
-void XTelepathySSOGoogleOperation::gotCredentials(KJob* kjob)
+void XTelepathySSOGoogleOperation::gotCredentials(KJob *kjob)
 {
     GetCredentialsJob *job = qobject_cast< GetCredentialsJob* >(kjob);
     QVariantMap credentialsData = job->credentialsData();
@@ -60,5 +67,7 @@ void XTelepathySSOGoogleOperation::gotCredentials(KJob* kjob)
     data.append("

-- 
ktp-auth-handler packaging



More information about the pkg-kde-commits mailing list