From 6ebf570486cf46011e1bf569a92de73b143535b6 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 8 Nov 2017 13:01:53 +0100 Subject: Doc: Remove Technology Preview status Change-Id: I01c49cfb4c18c01acc0ed762dcfc72ea027cd30f Reviewed-by: Venugopal Shivashankar --- src/oauth/doc/qtnetworkauth.qdocconf | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/oauth/doc/qtnetworkauth.qdocconf b/src/oauth/doc/qtnetworkauth.qdocconf index 246038e..485a1a7 100644 --- a/src/oauth/doc/qtnetworkauth.qdocconf +++ b/src/oauth/doc/qtnetworkauth.qdocconf @@ -35,6 +35,3 @@ exampledirs += ../../../examples/oauth navigation.landingpage = "Qt Network Authorization" navigation.cppclassespage = "Qt Network Authorization C++ Classes" - -# TODO: Remove once out of technology preview -navigation.homepage = "Qt Documentation (Technology Preview)" -- cgit v1.2.3 From 690baf09b95624040289bd8ced042094bac9a661 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 8 Nov 2017 12:58:37 +0100 Subject: Doc: Add highlighting for Twitter Timeline Example Task-number: QTBUG-60824 Change-Id: I229dc72963cac030a085e1d6988b9a2a9e7ff44a Reviewed-by: Venugopal Shivashankar --- src/oauth/doc/qtnetworkauth.qdocconf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/oauth/doc/qtnetworkauth.qdocconf b/src/oauth/doc/qtnetworkauth.qdocconf index 485a1a7..153e3ae 100644 --- a/src/oauth/doc/qtnetworkauth.qdocconf +++ b/src/oauth/doc/qtnetworkauth.qdocconf @@ -33,5 +33,7 @@ sourcedirs += .. examplesinstallpath = oauth exampledirs += ../../../examples/oauth +manifestmeta.highlighted.names = "QtNetworkAuth/Twitter Timeline Example" + navigation.landingpage = "Qt Network Authorization" navigation.cppclassespage = "Qt Network Authorization C++ Classes" -- cgit v1.2.3 From f4be387c8c787c56487767e7325e551becfca196 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Thu, 7 Sep 2017 15:16:44 +0200 Subject: Document QAbstractOAuthReplyHandler class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib3e478b7653702cf6d69978d3212f35484ee4702 Reviewed-by: Edward Welbourne Reviewed-by: Topi Reiniö --- src/oauth/qabstractoauthreplyhandler.cpp | 84 ++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/src/oauth/qabstractoauthreplyhandler.cpp b/src/oauth/qabstractoauthreplyhandler.cpp index 29fa635..001ebed 100644 --- a/src/oauth/qabstractoauthreplyhandler.cpp +++ b/src/oauth/qabstractoauthreplyhandler.cpp @@ -36,27 +36,91 @@ Q_LOGGING_CATEGORY(lcReplyHandler, "qt.networkauth.replyhandler") QT_BEGIN_NAMESPACE +/*! + \class QAbstractOAuthReplyHandler + \inmodule QtNetworkAuth + \ingroup oauth + \brief Handles replies to OAuth authentication requests + \since 5.8 + + The QAbstractOAuthReplyHandler class handles the answers + to all OAuth authentication requests. + This class is designed as a base whose subclasses implement + custom behavior in the callback() and networkReplyFinished() + methods. +*/ + +/*! + \fn QString QAbstractOAuthReplyHandler::callback() const + + Returns an absolute URI that the server will redirect the + resource owner back to when the Resource Owner Authorization step + is completed. If the client is unable to receive callbacks or a + callback URI has been established via other means, the parameter + value \b must be set to "oob" (all lower-case), to indicate an + out-of-band configuration. + + Derived classes should implement this function to provide the + expected callback type. +*/ + +/*! + \fn void QAbstractOAuthReplyHandler::networkReplyFinished(QNetworkReply *reply) + + After the server determines whether the request is valid this + function will be called. Reimplement it to get the data received + from the server wrapped in \a reply. +*/ + +/*! + \fn void QAbstractOAuthReplyHandler::callbackReceived(const QVariantMap &values) + + This signal is emitted when the reply from the server is + received, with \a values containing the token credentials + and any additional information the server may have returned. + When this signal is emitted, the authorization process + is complete. +*/ + +/*! + \fn void QAbstractOAuthReplyHandler::tokensReceived(const QVariantMap &tokens) + + This signal is emitted when new \a tokens are received from the + server. +*/ + +/*! + \fn void QAbstractOAuthReplyHandler::replyDataReceived(const QByteArray &data) + + This signal is emitted when an HTTP request finishes and the + data is available. \a data contains the response before parsing. +*/ + +/*! + \fn void QAbstractOAuthReplyHandler::callbackDataReceived(const QByteArray &data) + + This signal is emitted when a callback request is received: + \a data contains the information before parsing. +*/ + +/*! + Constructs a reply handler as a child of \a parent. +*/ QAbstractOAuthReplyHandler::QAbstractOAuthReplyHandler(QObject *parent) : QObject(parent) {} +/*! + Destroys the reply handler. +*/ QAbstractOAuthReplyHandler::~QAbstractOAuthReplyHandler() {} +/*! \internal */ QAbstractOAuthReplyHandler::QAbstractOAuthReplyHandler(QObjectPrivate &d, QObject *parent) : QObject(d, parent) {} -/*! - \class QAbstractOAuthReplyHandler - \inmodule QtNetworkAuth - \ingroup oauth - \brief Handles replies to OAuth authentication requests - \since 5.8 - - The QAbstractOAuthReplyHandler class handles the answers - to all OAuth authentication requests -*/ QT_END_NAMESPACE #endif // QT_NO_HTTP -- cgit v1.2.3 From eee494c12a70fa0aa6fce427f47f44ff60281dca Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 12 Dec 2017 09:56:00 +0100 Subject: Bump version Change-Id: Iea6b26671f64187feee7a3e4c2fe21c68b16a602 --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index 4e1c1b3..eccc77f 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ load(qt_build_config) CONFIG += warning_clean -MODULE_VERSION = 5.9.3 +MODULE_VERSION = 5.9.4 -- cgit v1.2.3 From ff679d2ff87894908470e9fb2edc5d149f0858c0 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 20 Dec 2017 12:07:19 +0100 Subject: Bump version Change-Id: I48d6a7ac8df4906c5bde304ab91546a3a68efa8b --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index 62a7693..8fae318 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -2,4 +2,4 @@ load(qt_build_config) CONFIG += warning_clean -MODULE_VERSION = 5.10.0 +MODULE_VERSION = 5.10.1 -- cgit v1.2.3 From f6aedc74c4a95440e649b625b6272f29e7f5fa71 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Thu, 21 Dec 2017 21:28:29 +0100 Subject: Fix QOAuth1::tokenSecret() return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit c071b588ce2b4d474845d553aa83120747dc46da broke QOAuth1::tokenSecret(), in fact, it were returning the clientIdentifierSharedKey instead. [ChangeLog][QOAuth1] Fix tokenSecret() return value. Task-number: QTBUG-65422 Change-Id: I72d6783220e7a030eac65e5c22e4421a1d6b106e Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Jesus Fernandez --- src/oauth/qoauth1.cpp | 2 +- tests/auto/oauth1/tst_oauth1.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/oauth/qoauth1.cpp b/src/oauth/qoauth1.cpp index 581ce4a..fcff92e 100644 --- a/src/oauth/qoauth1.cpp +++ b/src/oauth/qoauth1.cpp @@ -391,7 +391,7 @@ void QOAuth1::setClientCredentials(const QString &clientIdentifier, QString QOAuth1::tokenSecret() const { Q_D(const QOAuth1); - return d->clientIdentifierSharedKey; + return d->tokenSecret; } /*! Sets \a tokenSecret as the current token secret used to sign diff --git a/tests/auto/oauth1/tst_oauth1.cpp b/tests/auto/oauth1/tst_oauth1.cpp index 50822bd..7bfc628 100644 --- a/tests/auto/oauth1/tst_oauth1.cpp +++ b/tests/auto/oauth1/tst_oauth1.cpp @@ -145,6 +145,7 @@ public Q_SLOTS: private Q_SLOTS: void clientIdentifierSignal(); void clientSharedSecretSignal(); + void tokenSignal(); void tokenSecretSignal(); void temporaryCredentialsUrlSignal(); void temporaryTokenCredentialsUrlSignal(); @@ -252,7 +253,7 @@ void tst_OAuth1::clientSharedSecretSignal() PropertyTester::run(&QOAuth1::clientSharedSecretChanged, setters); } -void tst_OAuth1::tokenSecretSignal() +void tst_OAuth1::tokenSignal() { using PropertyTester = PropertyTester; PropertyTester::SetterFunctions setters { @@ -268,6 +269,22 @@ void tst_OAuth1::tokenSecretSignal() PropertyTester::run(&QOAuth1::tokenChanged, setters); } +void tst_OAuth1::tokenSecretSignal() +{ + using PropertyTester = PropertyTester; + PropertyTester::SetterFunctions setters { + [](QString *expectedValue, QOAuth1 *object) { + *expectedValue = "setTokenSecret"; + object->setTokenSecret(*expectedValue); + }, + [](QString *expectedValue, QOAuth1 *object) { + *expectedValue = "setTokenCredentials"; + object->setTokenCredentials(qMakePair(QString(), *expectedValue)); + } + }; + PropertyTester::run(&QOAuth1::tokenSecretChanged, setters); +} + void tst_OAuth1::temporaryCredentialsUrlSignal() { using PropertyTester = PropertyTester; -- cgit v1.2.3 From 8cce9fa16f3531e1e094a798c007480afa2bcaab Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Tue, 9 Jan 2018 11:24:34 +0100 Subject: Add two overload functions for put and post with QByteArray or QHttpMultiPart in QAbstractOAuth2 Task-number: QTBUG-65316 Change-Id: I893b2ad602de8c539ea08b72150dd1f92162b9dc Reviewed-by: Edward Welbourne Reviewed-by: Jesus Fernandez --- src/oauth/qabstractoauth2.cpp | 29 +++++++++++++++++++++++++++++ src/oauth/qabstractoauth2.h | 5 +++++ 2 files changed, 34 insertions(+) diff --git a/src/oauth/qabstractoauth2.cpp b/src/oauth/qabstractoauth2.cpp index 49c8f03..c01281b 100644 --- a/src/oauth/qabstractoauth2.cpp +++ b/src/oauth/qabstractoauth2.cpp @@ -40,6 +40,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -273,11 +274,25 @@ QNetworkReply *QAbstractOAuth2::post(const QUrl &url, const QVariantMap ¶met { Q_D(QAbstractOAuth2); const auto data = d->convertParameters(parameters); + return post(url, data); +} + +QNetworkReply *QAbstractOAuth2::post(const QUrl &url, const QByteArray &data) +{ + Q_D(QAbstractOAuth2); QNetworkReply *reply = d->networkAccessManager()->post(d->createRequest(url), data); connect(reply, &QNetworkReply::finished, [this, reply]() { emit finished(reply); }); return reply; } +QNetworkReply *QAbstractOAuth2::post(const QUrl &url, QHttpMultiPart *multiPart) +{ + Q_D(QAbstractOAuth2); + QNetworkReply *reply = d->networkAccessManager()->post(d->createRequest(url), multiPart); + connect(reply, &QNetworkReply::finished, [this, reply]() { emit finished(reply); }); + return reply; +} + /*! Sends an authenticated PUT request and returns a new QNetworkReply. The \a url and \a parameters are used to create @@ -290,11 +305,25 @@ QNetworkReply *QAbstractOAuth2::put(const QUrl &url, const QVariantMap ¶mete { Q_D(QAbstractOAuth2); const auto data = d->convertParameters(parameters); + return put(url, data); +} + +QNetworkReply *QAbstractOAuth2::put(const QUrl &url, const QByteArray &data) +{ + Q_D(QAbstractOAuth2); QNetworkReply *reply = d->networkAccessManager()->put(d->createRequest(url), data); connect(reply, &QNetworkReply::finished, std::bind(&QAbstractOAuth::finished, this, reply)); return reply; } +QNetworkReply *QAbstractOAuth2::put(const QUrl &url, QHttpMultiPart *multiPart) +{ + Q_D(QAbstractOAuth2); + QNetworkReply *reply = d->networkAccessManager()->put(d->createRequest(url), multiPart); + connect(reply, &QNetworkReply::finished, std::bind(&QAbstractOAuth::finished, this, reply)); + return reply; +} + /*! Sends an authenticated DELETE request and returns a new QNetworkReply. The \a url and \a parameters are used to create diff --git a/src/oauth/qabstractoauth2.h b/src/oauth/qabstractoauth2.h index 0f600b2..9262170 100644 --- a/src/oauth/qabstractoauth2.h +++ b/src/oauth/qabstractoauth2.h @@ -39,6 +39,7 @@ QT_BEGIN_NAMESPACE +class QHttpMultiPart; class QAbstractOAuth2Private; class Q_OAUTH_EXPORT QAbstractOAuth2 : public QAbstractOAuth { @@ -65,8 +66,12 @@ public: const QVariantMap ¶meters = QVariantMap()) override; Q_INVOKABLE QNetworkReply *post(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; + Q_INVOKABLE virtual QNetworkReply *post(const QUrl &url, const QByteArray &data); + Q_INVOKABLE virtual QNetworkReply *post(const QUrl &url, QHttpMultiPart *multiPart); Q_INVOKABLE QNetworkReply *put(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; + Q_INVOKABLE virtual QNetworkReply *put(const QUrl &url, const QByteArray &data); + Q_INVOKABLE virtual QNetworkReply *put(const QUrl &url, QHttpMultiPart *multiPart); Q_INVOKABLE QNetworkReply *deleteResource(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) override; -- cgit v1.2.3 From 272eaa037f3f8644a07f28c404d23c97bc88b560 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Fri, 12 Jan 2018 13:36:46 +0100 Subject: qtlite: Skip building examples when configured with no-feature-itemviews Task-number: QTBUG-53141 Change-Id: I3e8c685219cca550d00ee1335b0b233574c465ea Reviewed-by: Jesus Fernandez --- examples/oauth/redditclient/redditclient.pro | 1 + examples/oauth/twittertimeline/twittertimeline.pro | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/oauth/redditclient/redditclient.pro b/examples/oauth/redditclient/redditclient.pro index c507bed..456fc78 100644 --- a/examples/oauth/redditclient/redditclient.pro +++ b/examples/oauth/redditclient/redditclient.pro @@ -1,4 +1,5 @@ QT += widgets network networkauth +requires(qtConfig(listview)) TARGET = redditclient diff --git a/examples/oauth/twittertimeline/twittertimeline.pro b/examples/oauth/twittertimeline/twittertimeline.pro index 4448979..c0dcee2 100644 --- a/examples/oauth/twittertimeline/twittertimeline.pro +++ b/examples/oauth/twittertimeline/twittertimeline.pro @@ -1,4 +1,5 @@ QT = core widgets network networkauth +requires(qtConfig(tableview)) CONFIG -= app_bundle HEADERS += \ -- cgit v1.2.3 From a3495e515da0ffee896888cfa0f2d364b129ed2c Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Thu, 18 Jan 2018 15:08:13 +0100 Subject: Fix reading body incomplete body Sometimes the body was not available when reading. Change-Id: I2eab85b94b416ba1ed05a78732458b7eb5a5eb51 Reviewed-by: Edward Welbourne --- tests/auto/shared/webserver.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/auto/shared/webserver.h b/tests/auto/shared/webserver.h index 458c24a..b28a0e5 100644 --- a/tests/auto/shared/webserver.h +++ b/tests/auto/shared/webserver.h @@ -32,6 +32,7 @@ #include #include +#include #include class WebServer : public QTcpServer @@ -268,8 +269,14 @@ bool WebServer::HttpRequest::readBody(QTcpSocket *socket) return false; fragment.resize(bytesLeft); } - while (socket->bytesAvailable() && bytesLeft) - bytesLeft -= socket->read(&fragment.data()[fragment.size() - bytesLeft], bytesLeft); + while (bytesLeft) { + int got = socket->read(&fragment.data()[fragment.size() - bytesLeft], bytesLeft); + if (got < 0) + return false; // error + bytesLeft -= got; + if (bytesLeft) + qApp->processEvents(); + } fragment.swap(body); state = State::AllDone; return true; -- cgit v1.2.3 From cd3d1278f012b8f6b259305fd06006be7f825c99 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Thu, 18 Jan 2018 11:59:59 +0100 Subject: Add a basic OAuth2 test Change-Id: I62161dfdfd707a9e943516dde0c62abbb471ebad Reviewed-by: Edward Welbourne --- tests/auto/auto.pro | 1 + tests/auto/oauth2/oauth2.pro | 8 ++++ tests/auto/oauth2/tst_oauth2.cpp | 100 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/auto/oauth2/oauth2.pro create mode 100644 tests/auto/oauth2/tst_oauth2.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 41f3293..a0bbb36 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -3,6 +3,7 @@ TEMPLATE = subdirs SUBDIRS += \ cmake \ oauth1 \ + oauth2 \ oauth1signature \ oauthhttpserverreplyhandler diff --git a/tests/auto/oauth2/oauth2.pro b/tests/auto/oauth2/oauth2.pro new file mode 100644 index 0000000..74f3fda --- /dev/null +++ b/tests/auto/oauth2/oauth2.pro @@ -0,0 +1,8 @@ +TEMPLATE = app +CONFIG += testcase +TARGET = tst_oauth2 +SOURCES += tst_oauth2.cpp + +include(../shared/shared.pri) + +QT = core core-private network networkauth networkauth-private testlib diff --git a/tests/auto/oauth2/tst_oauth2.cpp b/tests/auto/oauth2/tst_oauth2.cpp new file mode 100644 index 0000000..826be06 --- /dev/null +++ b/tests/auto/oauth2/tst_oauth2.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include +#include + +#include "webserver.h" + +class tst_OAuth2 : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void getToken(); +}; + +struct ReplyHandler : QAbstractOAuthReplyHandler +{ + QString callback() const override + { + return QLatin1String("test"); + } + + void networkReplyFinished(QNetworkReply *reply) override + { + QVariantMap data; + const auto items = QUrlQuery(reply->readAll()).queryItems(); + for (const auto &pair : items) + data.insert(pair.first, pair.second); + Q_EMIT tokensReceived(data); + } + + void emitCallbackReceived(const QVariantMap &data) + { + Q_EMIT callbackReceived(data); + } +}; + +void tst_OAuth2::getToken() +{ + WebServer webServer([](const WebServer::HttpRequest &request, QTcpSocket *socket) { + if (request.url.path() == QLatin1String("/accessToken")) { + const QString text = "access_token=token&token_type=bearer"; + const QByteArray replyMessage { + "HTTP/1.0 200 OK\r\n" + "Content-Type: application/x-www-form-urlencoded; charset=\"utf-8\"\r\n" + "Content-Length: " + QByteArray::number(text.size()) + "\r\n\r\n" + + text.toUtf8() + }; + socket->write(replyMessage); + } + }); + QOAuth2AuthorizationCodeFlow oauth2; + oauth2.setAuthorizationUrl(webServer.url(QLatin1String("authorization"))); + oauth2.setAccessTokenUrl(webServer.url(QLatin1String("accessToken"))); + auto replyHandler = new ReplyHandler; + oauth2.setReplyHandler(replyHandler); + connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, [&](const QUrl &url) { + const QUrlQuery query(url.query()); + replyHandler->emitCallbackReceived(QVariantMap { + { QLatin1String("code"), QLatin1String("test") }, + { QLatin1String("state"), + query.queryItemValue(QLatin1String("state")) } + }); + }); + QSignalSpy grantedSpy(&oauth2, &QOAuth2AuthorizationCodeFlow::granted); + oauth2.grant(); + QTRY_COMPARE(grantedSpy.count(), 1); + QCOMPARE(oauth2.token(), QLatin1String("token")); +} + +QTEST_MAIN(tst_OAuth2) +#include "tst_oauth2.moc" -- cgit v1.2.3