Commit 7072c2cf authored by Jesus Fernandez's avatar Jesus Fernandez

Initial commit

parents
INCLUDEPATH += $$IN_PWD/QtOAuth
DEPENDPATH += $$OUT_PWD/../QtOAuth
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../QtOAuth/release/ -lQtOAuth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../QtOAuth/debug/ -lQtOAuth
else:unix: LIBS += -L$$OUT_PWD/../QtOAuth/ -lQtOAuth
TEMPLATE = subdirs
SUBDIRS += QtOAuth twittertimeline redditclient
TEMPLATE = lib
TARGET = QtOAuth
INCLUDEPATH += .
QT += core core-private network
# Input
HEADERS += qabstractoauth.h \
qabstractoauth2.h \
private/qabstractoauth2_p.h \
private/qabstractoauth_p.h \
qabstractoauthreplyhandler.h \
qoauth1.h \
private/qoauth1_p.h \
qoauth2authorizationcodeflow.h \
private/qoauth2authorizationcodeflow_p.h \
qoauth2implicitgrantflow.h \
private/qoauth2implicitgrantflow_p.h \
qoauthhttpserverreplyhandler.h \
private/qoauthhttpserverreplyhandler_p.h \
qoauthoobreplyhandler.h
SOURCES += qabstractoauth.cpp \
qabstractoauth2.cpp \
qabstractoauthreplyhandler.cpp \
qoauth1.cpp \
qoauth2authorizationcodeflow.cpp \
qoauth2implicitgrantflow.cpp \
qoauthhttpserverreplyhandler.cpp \
qoauthoobreplyhandler.cpp
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QABSTRACTOAUTH2_P_H
#define QABSTRACTOAUTH2_P_H
#ifndef QT_NO_HTTP
#include <qabstractoauth2.h>
#include <private/qabstractoauth_p.h>
#include <QtCore/qurl.h>
#include <QtCore/qstring.h>
#include <QtCore/qpointer.h>
#include <QtNetwork/qnetworkreply.h>
QT_BEGIN_NAMESPACE
class QNetworkAccessManager;
class QAbstractOAuth2Private : public QAbstractOAuthPrivate
{
Q_DECLARE_PUBLIC(QAbstractOAuth2)
public:
QAbstractOAuth2Private(QNetworkAccessManager *manager);
~QAbstractOAuth2Private();
QString verifier;
QString scope;
QString apiKey;
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QABSTRACTOAUTH2_P_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QABSTRACTQOAUTH_P_H
#define QABSTRACTQOAUTH_P_H
#ifndef QT_NO_HTTP
#include <qabstractoauth.h>
#include <qoauthoobreplyhandler.h>
#include <private/qobject_p.h>
#include <QtCore/qurl.h>
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
#include <QtCore/qscopedpointer.h>
#include <QtNetwork/qtcpserver.h>
QT_BEGIN_NAMESPACE
class QUrlQuery;
class Q_AUTOTEST_EXPORT QAbstractOAuthPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QAbstractOAuth)
public:
QAbstractOAuthPrivate(QNetworkAccessManager *manager);
~QAbstractOAuthPrivate();
void setStatus(QAbstractOAuth::Status status);
QOAuthTokenPair clientId;
QString redirectUri;
QOAuthTokenPair token;
QOAuthTokenPair accessToken;
QUrl requestTokenUrl;
QUrl authorizationGrantUrl;
QVariantMap extraTokens;
QAbstractOAuth::Status status;
QNetworkAccessManager::Operation operation;
QScopedPointer<QAbstractOAuthReplyHandler> replyHandler;
QScopedPointer<QOAuthOobReplyHandler> defaultReplyHandler;
QNetworkAccessManager *networkAccessManager;
static QUrlQuery createQuery(const QVariantMap &parameters);
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QABSTRACTQOAUTH_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QOAUTH1_P_H
#define QOAUTH1_P_H
#ifndef QT_NO_HTTP
#include <qoauth1.h>
#include <private/qabstractoauth_p.h>
#include <QtCore/qurl.h>
#include <QtCore/qobject.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qnetworkaccessmanager.h>
QT_BEGIN_NAMESPACE
class QOAuth1Private : public QAbstractOAuthPrivate
{
Q_DECLARE_PUBLIC(QOAuth1)
public:
QOAuth1Private(QNetworkAccessManager *networkAccessManager);
QString verifier;
// private slots
void _q_onTokenRequestFinished();
void _q_onTokenRequestError(QNetworkReply::NetworkError error);
void _q_onTokenExchangeError(QNetworkReply::NetworkError error);
void _q_requestAuthorizationGrantAnswer();
void _q_tokensReceived(const QVariantMap &tokens);
void appendCommonHeaders(QVariantMap *headers);
void appendSignature(QVariantMap *headers,
const QUrl &url,
QNetworkAccessManager::Operation operation,
const QVariantMap parameters);
QNetworkReply *requestToken(QNetworkAccessManager::Operation operation, const QUrl &url,
const QVariantMap &additionalParameters);
QNetworkReply *requestAuthorizationGrant(QNetworkAccessManager::Operation operation,
const QUrl &url,
const QVariantMap &additionalParameters);
QAbstractOAuth::SignatureMethod signatureMethod;
QString signatureMethodString() const;
static QString operationName(QNetworkAccessManager::Operation op);
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QOAUTH1_P_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QOAUTH2AUTHORIZATIONCODEFLOW_P_H
#define QOAUTH2AUTHORIZATIONCODEFLOW_P_H
#ifndef QT_NO_HTTP
#include <qoauth2authorizationcodeflow.h>
#include <private/qabstractoauth2_p.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
QT_BEGIN_NAMESPACE
class QOAuth2AuthorizationCodeFlowPrivate : public QAbstractOAuth2Private
{
Q_DECLARE_PUBLIC(QOAuth2AuthorizationCodeFlow)
public:
QOAuth2AuthorizationCodeFlowPrivate(QNetworkAccessManager *manager, quint16 port);
void handleCallback(const QVariantMap &data);
void accessTokenRequestFinished();
QString tokenType;
QDateTime expiresAt;
QString refreshToken;
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QOAUTH2AUTHORIZATIONCODEFLOW_P_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QOAUTH2IMPLICITGRANTFLOW_P_H
#define QOAUTH2IMPLICITGRANTFLOW_P_H
#ifndef QT_NO_HTTP
#include <qoauth2implicitgrantflow.h>
#include <private/qabstractoauth2_p.h>
QT_BEGIN_NAMESPACE
class QOAuth2ImplicitGrantFlowPrivate : public QAbstractOAuth2Private
{
Q_DECLARE_PUBLIC(QOAuth2ImplicitGrantFlow)
public:
QOAuth2ImplicitGrantFlowPrivate(QNetworkAccessManager *manager);
~QOAuth2ImplicitGrantFlowPrivate();
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QOAUTH2IMPLICITGRANTFLOW_P_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of the Network Access API. This header file may change from
// version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QOAUTHHTTPSERVERREPLYHANDLER_P_H
#define QOAUTHHTTPSERVERREPLYHANDLER_P_H
#ifndef QT_NO_HTTP
#include <private/qobject_p.h>
#include "qoauthhttpserverreplyhandler.h"
#include <QtNetwork/qtcpserver.h>
QT_BEGIN_NAMESPACE
class QOAuthHttpServerReplyHandlerPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QOAuthHttpServerReplyHandler)
public:
explicit QOAuthHttpServerReplyHandlerPrivate(quint16 port);
~QOAuthHttpServerReplyHandlerPrivate();
QTcpServer httpServer;
QString text;
private:
void onClientConnected();
void answerClient();
};
QT_END_NAMESPACE
#endif // QT_NO_HTTP
#endif // QOAUTHHTTPSERVERREPLYHANDLER_P_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QT_NO_HTTP
#include <qabstractoauth.h>
#include <qabstractoauthreplyhandler.h>
#include <private/qabstractoauth_p.h>
#include <QtCore/qurl.h>
#include <QtCore/qpair.h>
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qurlquery.h>
#include <QtCore/qmessageauthenticationcode.h>
#include <QtNetwork/qnetworkrequest.h>
QT_BEGIN_NAMESPACE
Q_DECLARE_METATYPE(QAbstractOAuth::Error)
QAbstractOAuthPrivate::QAbstractOAuthPrivate(QNetworkAccessManager *manager)
: status(QAbstractOAuth::Status::NotAuthenticated)
, replyHandler(nullptr)
, defaultReplyHandler(new QOAuthOobReplyHandler)
, networkAccessManager(manager)
{
Q_ASSERT(manager);
}
QAbstractOAuthPrivate::~QAbstractOAuthPrivate()
{}
void QAbstractOAuthPrivate::setStatus(QAbstractOAuth::Status newStatus)
{
Q_Q(QAbstractOAuth);
if (status != newStatus) {
status = newStatus;
Q_EMIT q->statusChanged(status);
}
}
QUrlQuery QAbstractOAuthPrivate::createQuery(const QVariantMap &parameters)
{
QUrlQuery query;
for (auto it = parameters.begin(), end = parameters.end(); it != end; ++it)
query.addQueryItem(it.key(), it.value().toString());
return query;
}
//QAbstractOAuth::QAbstractOAuth(QObject *parent)
// : QObject(*new QAbstractOAuthPrivate, parent)
//{
// qRegisterMetaType<QAbstractOAuth::Error>();
//}
QAbstractOAuth::QAbstractOAuth(QAbstractOAuthPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
qRegisterMetaType<QAbstractOAuth::Error>();
}
QAbstractOAuth::~QAbstractOAuth()
{}