[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:58:34 UTC 2016


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

The following commit has been merged in the master branch:
commit 8eee839cb719ea6eff30be9edd75ed6ce0bc1e10
Author: Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
Date:   Fri Dec 23 15:31:05 2011 +0100

    Support X-MESSENGER-OAUTH2 authentication mechanism
    
    BUG: 289668
---
 CMakeLists.txt                                     |   3 +
 sasl-auth-op.cpp                                   |  16 ++-
 x-messenger-oauth2-auth-operation.cpp              | 121 ++++++++++++++++
 ...ration.h => x-messenger-oauth2-auth-operation.h |  26 ++--
 x-messenger-oauth2-prompt.cpp                      | 159 +++++++++++++++++++++
 x-messenger-oauth2-prompt.h                        |  58 ++++++++
 6 files changed, 369 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e92de5..32bbf84 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,6 +31,8 @@ set(ktp_auth_handler_SRCS
     types.cpp
     x-telepathy-password-auth-operation.cpp
     x-telepathy-password-prompt.cpp
+    x-messenger-oauth2-auth-operation.cpp
+    x-messenger-oauth2-prompt.cpp
     ${ktp_common_internals_SRCS}
 )
 
@@ -42,6 +44,7 @@ target_link_libraries(ktp-auth-handler
     ${QT_QTGUI_LIBRARY}
     ${QT_QTXML_LIBRARY}
     ${QT_QTCORE_LIBRARY}
+    ${QT_QTWEBKIT_LIBRARY}
     ${TELEPATHY_QT4_LIBRARIES}
     ${KTP_LIBRARIES}
     ${KDE4_KDECORE_LIBS}
diff --git a/sasl-auth-op.cpp b/sasl-auth-op.cpp
index f78eaf8..1b46725 100644
--- a/sasl-auth-op.cpp
+++ b/sasl-auth-op.cpp
@@ -20,6 +20,7 @@
 
 #include "sasl-auth-op.h"
 #include "x-telepathy-password-auth-operation.h"
+#include "x-messenger-oauth2-auth-operation.h"
 
 #include <TelepathyQt/PendingVariantMap>
 
@@ -68,11 +69,22 @@ void SaslAuthOp::gotProperties(Tp::PendingOperation *op)
         QString error = qdbus_cast<QString>(props.value("SASLError"));
         QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
         authop->onSASLStatusChanged(status, error, errorDetails);
+    } else if (mechanisms.contains(QLatin1String("X-MESSENGER-OAUTH2"))) {
+        // everything ok, we can return from handleChannels now
+        emit ready(this);
+        XMessengerOAuth2AuthOperation *authop = new XMessengerOAuth2AuthOperation(m_account, m_saslIface);
+        connect (authop,
+                 SIGNAL(finished(Tp::PendingOperation*)),
+                 SLOT(onAuthOperationFinished(Tp::PendingOperation*)));
+        uint status = qdbus_cast<uint>(props.value("SASLStatus"));
+        QString error = qdbus_cast<QString>(props.value("SASLError"));
+        QVariantMap errorDetails = qdbus_cast<QVariantMap>(props.value("SASLErrorDetails"));
+        authop->onSASLStatusChanged(status, error, errorDetails);
     } else {
-        kWarning() << "X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available:" << mechanisms;
+        kWarning() << "X-TELEPATHY-PASSWORD and X-MESSENGER-OAUTH2 are the only supported SASL mechanism and are not available:" << mechanisms;
         m_channel->requestClose();
         setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,
-                QLatin1String("X-TELEPATHY-PASSWORD is the only supported SASL mechanism and is not available"));
+                QLatin1String("X-TELEPATHY-PASSWORD and X-MESSENGER-OAUTH2 are the only supported SASL mechanism and are not available"));
         return;
     }
 }
diff --git a/x-messenger-oauth2-auth-operation.cpp b/x-messenger-oauth2-auth-operation.cpp
new file mode 100644
index 0000000..03e96ce
--- /dev/null
+++ b/x-messenger-oauth2-auth-operation.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
+ *
+ * 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.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "x-messenger-oauth2-auth-operation.h"
+
+#include <KUrl>
+#include <KDebug>
+#include <KLocalizedString>
+#include <TelepathyQt/Account>
+#include <KTp/wallet-interface.h>
+
+const QLatin1String XMessengerOAuth2TokenWalletEntry("token");
+
+XMessengerOAuth2AuthOperation::XMessengerOAuth2AuthOperation(
+        const Tp::AccountPtr &account,
+        Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface) :
+    Tp::PendingOperation(account),
+    m_account(account),
+    m_saslIface(saslIface)
+{
+    connect(m_saslIface,
+            SIGNAL(SASLStatusChanged(uint,QString,QVariantMap)),
+            SLOT(onSASLStatusChanged(uint,QString,QVariantMap)));
+}
+
+XMessengerOAuth2AuthOperation::~XMessengerOAuth2AuthOperation()
+{
+}
+
+void XMessengerOAuth2AuthOperation::onSASLStatusChanged(uint status, const QString &reason,
+        const QVariantMap &details)
+{
+    KTp::WalletInterface wallet(0);
+
+    switch (status) {
+        case Tp::SASLStatusNotStarted :
+            if (wallet.hasEntry(m_account, XMessengerOAuth2TokenWalletEntry)) {
+                m_saslIface->StartMechanismWithData(QLatin1String("X-MESSENGER-OAUTH2"),
+                                                    QByteArray::fromBase64(wallet.entry(m_account, XMessengerOAuth2TokenWalletEntry).toLatin1()));
+                return;
+            }
+
+            kDebug() << "Requesting password";
+            m_dialog = new XMessengerOAuth2Prompt();
+
+            connect(m_dialog.data(),
+                    SIGNAL(finished(int)),
+                    SLOT(onDialogFinished(int)));
+            // Show the dialog only when the login page is loaded
+            connect(m_dialog.data(),
+                    SIGNAL(loginPageLoaded(bool)),
+                    m_dialog.data(),
+                    SLOT(show()));
+            break;
+        case Tp::SASLStatusServerSucceeded:
+            kDebug() << "Authentication handshake";
+            m_saslIface->AcceptSASL();
+            break;
+        case Tp::SASLStatusSucceeded:
+            kDebug() << "Authentication succeeded";
+            setFinished();
+            break;
+        case Tp::SASLStatusInProgress:
+            kDebug() << "Authenticating...";
+            break;
+        case Tp::SASLStatusServerFailed:
+        {
+            kDebug() << "Error authenticating - reason:" << reason << "- details:" << details;
+            QString errorMessage = details[QLatin1String("server-message")].toString();
+            setFinishedWithError(reason, errorMessage.isEmpty() ? i18n("Authentication error") : errorMessage);
+            break;
+        }
+        default:
+            kWarning() << "Unhandled status" << status;
+            Q_ASSERT(false);
+            break;
+    }
+}
+
+void XMessengerOAuth2AuthOperation::onDialogFinished(int result)
+{
+    KTp::WalletInterface wallet(0);
+    switch (result) {
+        case QDialog::Rejected:
+            kDebug() << "Authentication cancelled";
+            m_saslIface->AbortSASL(Tp::SASLAbortReasonUserAbort, "User cancelled auth");
+            setFinished();
+            if (!m_dialog.isNull()) {
+                m_dialog.data()->deleteLater();
+            }
+            return;
+        case QDialog::Accepted:
+            kDebug() << QLatin1String(m_dialog.data()->accessToken());
+            wallet.setEntry(m_account, XMessengerOAuth2TokenWalletEntry, m_dialog.data()->accessToken().toBase64());
+            m_saslIface->StartMechanismWithData(QLatin1String("X-MESSENGER-OAUTH2"), m_dialog.data()->accessToken());
+            if (!m_dialog.isNull()) {
+                m_dialog.data()->deleteLater();
+            }
+            return;
+        default:
+            Q_ASSERT(false);
+            break;
+    }
+}
+
+#include "x-messenger-oauth2-auth-operation.moc"
diff --git a/x-telepathy-password-auth-operation.h b/x-messenger-oauth2-auth-operation.h
similarity index 72%
copy from x-telepathy-password-auth-operation.h
copy to x-messenger-oauth2-auth-operation.h
index 29dddfc..8479f08 100644
--- a/x-telepathy-password-auth-operation.h
+++ b/x-messenger-oauth2-auth-operation.h
@@ -16,37 +16,39 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef X_TELEPATHY_PASSWORD_AUTH_OPERATION_H
-#define X_TELEPATHY_PASSWORD_AUTH_OPERATION_H
+#ifndef X_MESSENGER_OAUTH2_AUTH_OPERATION_H
+#define X_MESSENGER_OAUTH2_AUTH_OPERATION_H
 
 #include <TelepathyQt/PendingOperation>
 #include <TelepathyQt/Channel>
 #include <TelepathyQt/Types>
 
-class XTelepathyPasswordAuthOperation : public Tp::PendingOperation
+#include "x-messenger-oauth2-prompt.h"
+
+class XMessengerOAuth2AuthOperation : public Tp::PendingOperation
 {
     Q_OBJECT
-    Q_DISABLE_COPY(XTelepathyPasswordAuthOperation)
+    Q_DISABLE_COPY(XMessengerOAuth2AuthOperation)
 
 public:
-    explicit XTelepathyPasswordAuthOperation(
+    explicit XMessengerOAuth2AuthOperation(
             const Tp::AccountPtr &account,
-            Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface,
-            bool canTryAgain);
-    ~XTelepathyPasswordAuthOperation();
+            Tp::Client::ChannelInterfaceSASLAuthenticationInterface *saslIface);
+    ~XMessengerOAuth2AuthOperation();
 
 protected Q_SLOTS:
     void onSASLStatusChanged(uint status, const QString &reason, const QVariantMap &details);
 
-private:
-    void promptUser(bool isFirstPrompt);
+private Q_SLOTS:
+    void onDialogFinished(int result);
 
+private:
     Tp::AccountPtr m_account;
     Tp::Client::ChannelInterfaceSASLAuthenticationInterface *m_saslIface;
-    bool m_canTryAgain;
+    QWeakPointer<XMessengerOAuth2Prompt> m_dialog;
 
     friend class SaslAuthOp;
 };
 
 
-#endif // X_TELEPATHY_PASSWORD_AUTH_OPERATION_H
+#endif // X_MESSENGER_OAUTH2_AUTH_OPERATION_H
diff --git a/x-messenger-oauth2-prompt.cpp b/x-messenger-oauth2-prompt.cpp
new file mode 100644
index 0000000..cf26208
--- /dev/null
+++ b/x-messenger-oauth2-prompt.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
+ *
+ * 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.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "x-messenger-oauth2-prompt.h"
+
+#include <KUrl>
+#include <KIcon>
+#include <KToolInvocation>
+#include <KDebug>
+
+#include <QtWebKit/QWebView>
+#include <QtWebKit/QWebSettings>
+#include <QtGui/QProgressBar>
+#include <QtGui/QBoxLayout>
+#include <QtGui/QLayout>
+#include <QtNetwork/QNetworkReply>
+
+
+const QLatin1String msnClientID("000000004C070A47");
+const QLatin1String redirectUri("https://oauth.live.com/desktop");
+
+XMessengerOAuth2Prompt::XMessengerOAuth2Prompt(QWidget* parent) :
+    KDialog(parent),
+    m_webView(new QWebView()),
+    m_ProgressBar(new QProgressBar()),
+    m_loginPageLoaded(false)
+{
+    // TODO Use .ui file
+    m_webView->setContextMenuPolicy(Qt::NoContextMenu);
+//    QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+    m_ProgressBar->setRange(0, 100);
+
+    QVBoxLayout *layout = new QVBoxLayout(this);
+    layout->setContentsMargins(0, 0, 0, 0);
+    layout->addWidget(m_webView);
+    layout->addWidget(m_ProgressBar);
+
+    QWidget *widget = new QWidget(this);
+    widget->setLayout(layout);
+    widget->setContentsMargins(0, 0, 0, 0);
+
+    setMainWidget(widget);
+    setWindowIcon(KIcon("telepathy-kde"));
+    setButtons(Cancel);
+
+    // connect progress bar
+    connect(m_webView,
+            SIGNAL(loadFinished(bool)),
+            m_ProgressBar,
+            SLOT(hide()));
+    connect(m_webView,
+            SIGNAL(loadStarted()),
+            m_ProgressBar,
+            SLOT(show()));
+    connect(m_webView,
+            SIGNAL(loadProgress(int)),
+            m_ProgressBar,
+            SLOT(setValue(int)));
+
+    connect(m_webView,
+            SIGNAL(urlChanged(QUrl)),
+            SLOT(onUrlChanged(QUrl)));
+    connect(m_webView,
+            SIGNAL(loadFinished(bool)),
+            SLOT(onLoadFinished(bool)));
+
+    connect(m_webView,
+            SIGNAL(linkClicked(QUrl)),
+            SLOT(onLinkClicked(QUrl)));
+
+    m_webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+    m_webView->page()->setForwardUnsupportedContent(true);
+
+    connect(m_webView->page(),
+            SIGNAL(unsupportedContent(QNetworkReply*)),
+            SLOT(onUnsupportedContent(QNetworkReply*)));
+
+    // start loading the login URL
+    KUrl url(QString(QLatin1String("https://oauth.live.com/authorize?response_type=token&redirect_uri=%1&client_id=%2&scope=wl.messenger")).arg(redirectUri).arg(msnClientID));
+    m_webView->load(url.url());
+}
+
+XMessengerOAuth2Prompt::~XMessengerOAuth2Prompt()
+{
+}
+
+QByteArray XMessengerOAuth2Prompt::accessToken() const
+{
+    return m_accessToken;
+}
+
+QSize XMessengerOAuth2Prompt::sizeHint() const
+{
+    return QSize(500, 600);
+}
+
+void XMessengerOAuth2Prompt::onUrlChanged(const QUrl &url)
+{
+    // FIXME: This method is left for debugging purpose
+    kDebug() << url;
+    kDebug() << m_webView->url();
+}
+
+void XMessengerOAuth2Prompt::onLinkClicked(const QUrl& url)
+{
+    kDebug() << url;
+    KToolInvocation::invokeBrowser(url.toString());
+}
+
+void XMessengerOAuth2Prompt::onLoadFinished(bool ok)
+{
+    if (!m_loginPageLoaded) {
+        m_loginPageLoaded = true;
+        Q_EMIT loginPageLoaded(ok);
+    }
+}
+
+void XMessengerOAuth2Prompt::onUnsupportedContent(QNetworkReply* reply)
+{
+    // For some reason the request for the token is unsupported, but we
+    // Can extract the token from the url of the failing request
+    // FIXME: In the future this might need to be fixed
+    QUrl url =  reply->url();
+    if (url.toString().indexOf(redirectUri) != 0) {
+        // This is not the url containing the token
+        return;
+    }
+    QString accessToken = url.encodedFragment();   // Get the URL fragment part
+    accessToken = accessToken.split("&").first();  // Remove the "expires_in" part.
+    accessToken = accessToken.split("=").at(1);    // Split by "access_token=..." and take latter part
+
+    // Wocky will base64 encode, but token actually already is base64, so we
+    // decode now and it will be re-encoded.
+    m_accessToken = QByteArray::fromBase64(QByteArray::fromPercentEncoding(accessToken.toUtf8()));
+    kDebug() << "size = " << m_accessToken.size();
+    char* data = QByteArray::fromBase64(QByteArray::fromPercentEncoding(accessToken.toUtf8())).data();
+    for (int i = 0; i < m_accessToken.size(); i++, data++) {
+     kDebug() << i << "[" << *data << "]" << endl;
+    }
+    Q_EMIT accessTokenTaken(m_accessToken);
+    accept();
+}
+
+#include "x-messenger-oauth2-prompt.moc"
diff --git a/x-messenger-oauth2-prompt.h b/x-messenger-oauth2-prompt.h
new file mode 100644
index 0000000..b3b2e06
--- /dev/null
+++ b/x-messenger-oauth2-prompt.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli at gmail.com>
+ *
+ * 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.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef X_MESSENGER_OAUTH2_PROMPT_H
+#define X_MESSENGER_OAUTH2_PROMPT_H
+
+#include <KDialog>
+
+class QProgressBar;
+class QWebView;
+class QNetworkReply;
+
+class XMessengerOAuth2Prompt : public KDialog
+{
+    Q_OBJECT
+
+public:
+    explicit XMessengerOAuth2Prompt(QWidget *parent = 0);
+    ~XMessengerOAuth2Prompt();
+
+    QByteArray accessToken() const;
+
+protected:
+    virtual QSize sizeHint() const;
+
+Q_SIGNALS:
+    void loginPageLoaded(bool ok);
+    void accessTokenTaken(const QByteArray &accessToken);
+
+private Q_SLOTS:
+    void onUrlChanged(const QUrl &url);
+    void onLinkClicked(const QUrl &url);
+    void onLoadFinished(bool);
+    void onUnsupportedContent(QNetworkReply* reply);
+
+private:
+    QWebView *m_webView;
+    QProgressBar *m_ProgressBar;
+    bool m_loginPageLoaded;
+    QByteArray m_accessToken;
+};
+
+#endif // X_MESSENGER_OAUTH2_PROMPT_H

-- 
ktp-auth-handler packaging



More information about the pkg-kde-commits mailing list