Commit e3fc27ca authored by Jesus Fernandez's avatar Jesus Fernandez

Removed port

parent fcdb9f99
......@@ -72,12 +72,11 @@ class OAUTH_EXPORT QAbstractOAuth2Private : public QAbstractOAuthPrivate
Q_DECLARE_PUBLIC(QAbstractOAuth2)
public:
QAbstractOAuth2Private(QNetworkAccessManager *manager = nullptr, quint16 port = 0);
QAbstractOAuth2Private(QNetworkAccessManager *manager = nullptr);
~QAbstractOAuth2Private();
static QString generateRandomState();
quint16 port = 0;
QPair<QString, QString> clientCredentials;
QString token;
QString scope;
......
......@@ -67,8 +67,7 @@ class OAUTH_EXPORT QOAuth2AuthorizationCodeFlowPrivate : public QAbstractOAuth2P
Q_DECLARE_PUBLIC(QOAuth2AuthorizationCodeFlow)
public:
QOAuth2AuthorizationCodeFlowPrivate(quint16 port = 0);
QOAuth2AuthorizationCodeFlowPrivate(QNetworkAccessManager *manager, quint16 port);
QOAuth2AuthorizationCodeFlowPrivate(QNetworkAccessManager *manager = nullptr);
void handleCallback(const QVariantMap &data);
void accessTokenRequestFinished(QNetworkReply *reply);
......
......@@ -73,9 +73,8 @@ const QString Key::state = QStringLiteral("state");
const QString Key::tokenType = QStringLiteral("token_type");
QAbstractOAuth2Private::QAbstractOAuth2Private(QNetworkAccessManager *manager, quint16 port)
: QAbstractOAuthPrivate(manager)
, port(port)
QAbstractOAuth2Private::QAbstractOAuth2Private(QNetworkAccessManager *manager) :
QAbstractOAuthPrivate(manager)
{}
QAbstractOAuth2Private::~QAbstractOAuth2Private()
......@@ -97,12 +96,12 @@ QString QAbstractOAuth2Private::generateRandomState()
return string;
}
QAbstractOAuth2::QAbstractOAuth2(QNetworkAccessManager *manager, QObject *parent)
: QAbstractOAuth(*new QAbstractOAuth2Private(manager), parent)
QAbstractOAuth2::QAbstractOAuth2(QNetworkAccessManager *manager, QObject *parent) :
QAbstractOAuth(*new QAbstractOAuth2Private(manager), parent)
{}
QAbstractOAuth2::QAbstractOAuth2(QAbstractOAuth2Private &dd, QObject *parent)
: QAbstractOAuth(dd, parent)
QAbstractOAuth2::QAbstractOAuth2(QAbstractOAuth2Private &dd, QObject *parent) :
QAbstractOAuth(dd, parent)
{}
QAbstractOAuth2::~QAbstractOAuth2()
......@@ -286,26 +285,6 @@ void QAbstractOAuth2::setToken(const QString &token)
}
}
uint QAbstractOAuth2::port() const
{
Q_D(const QAbstractOAuth2);
return d->port;
}
void QAbstractOAuth2::setPort(uint port)
{
if (port > std::numeric_limits<quint16>::max()) {
qWarning("QAbstractOAuth2::setPort: port %d is invalid. It must be in the range 0-65535.",
port);
return;
}
Q_D(QAbstractOAuth2);
if (d->port != port) {
d->port = port;
Q_EMIT portChanged(port);
}
}
QString QAbstractOAuth2::state() const
{
Q_D(const QAbstractOAuth2);
......
......@@ -59,7 +59,6 @@ class OAUTH_EXPORT QAbstractOAuth2 : public QAbstractOAuth
READ clientIdentifierSharedKey
WRITE setClientIdentifierSharedKey
NOTIFY clientIdentifierSharedKeyChanged)
Q_PROPERTY(uint port READ port WRITE setPort NOTIFY portChanged)
Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
public:
......@@ -94,9 +93,6 @@ public:
QString token() const;
void setToken(const QString &token);
uint port() const;
void setPort(uint port);
QString state() const;
void setState(const QString &state);
......
......@@ -55,14 +55,8 @@
QT_BEGIN_NAMESPACE
QOAuth2AuthorizationCodeFlowPrivate::QOAuth2AuthorizationCodeFlowPrivate(quint16 port)
{
QAbstractOAuth2Private::port = port;
}
QOAuth2AuthorizationCodeFlowPrivate::QOAuth2AuthorizationCodeFlowPrivate(
QNetworkAccessManager *manager, quint16 port)
: QAbstractOAuth2Private(manager, port)
QNetworkAccessManager *manager) : QAbstractOAuth2Private(manager)
{}
void QOAuth2AuthorizationCodeFlowPrivate::handleCallback(const QVariantMap &data)
......@@ -164,21 +158,19 @@ void QOAuth2AuthorizationCodeFlowPrivate::authenticate(QNetworkReply *reply,
}
}
QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(QObject *parent)
: QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate, parent)
QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(QObject *parent) :
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate, parent)
{}
QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(QNetworkAccessManager *manager,
quint16 port,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager, port), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager), parent)
{}
QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &clientIdentifier,
QNetworkAccessManager *manager,
quint16 port,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager, port), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager), parent)
{
Q_D(QOAuth2AuthorizationCodeFlow);
d->clientCredentials.first = clientIdentifier;
......@@ -187,9 +179,8 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client
QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QUrl &authenticateUrl,
const QUrl &accessTokenUrl,
QNetworkAccessManager *manager,
quint16 port,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager, port), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager), parent)
{
Q_D(QOAuth2AuthorizationCodeFlow);
d->authorizationUrl = authenticateUrl;
......@@ -200,9 +191,8 @@ QOAuth2AuthorizationCodeFlow::QOAuth2AuthorizationCodeFlow(const QString &client
const QUrl &authenticateUrl,
const QUrl &accessTokenUrl,
QNetworkAccessManager *manager,
quint16 port,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager, port), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2AuthorizationCodeFlowPrivate(manager), parent)
{
Q_D(QOAuth2AuthorizationCodeFlow);
d->authorizationUrl = authenticateUrl;
......@@ -242,8 +232,6 @@ void QOAuth2AuthorizationCodeFlow::grant()
} else if (d->accessTokenUrl.isEmpty()) {
qCritical("QOAuth2AuthorizationCodeFlow: No request access token Url set");
return;
} else if (d->replyHandler.isNull()) {
d->replyHandler = new QOAuthHttpServerReplyHandler(d->port, this);
}
const QUrl url = buildAuthenticateUrl();
......
......@@ -62,25 +62,21 @@ class OAUTH_EXPORT QOAuth2AuthorizationCodeFlow : public QAbstractOAuth2
public:
explicit QOAuth2AuthorizationCodeFlow(QObject *parent = nullptr);
explicit QOAuth2AuthorizationCodeFlow(QNetworkAccessManager *manager,
quint16 port = 0,
QObject *parent = nullptr);
QOAuth2AuthorizationCodeFlow(const QString &clientIdentifier,
QNetworkAccessManager *manager,
quint16 port = 0,
QObject *parent = nullptr);
QOAuth2AuthorizationCodeFlow(const QUrl &authorizationUrl,
const QUrl &accessTokenUrl,
QNetworkAccessManager *manager,
quint16 port = 0,
QObject *parent = nullptr);
QOAuth2AuthorizationCodeFlow(const QString &clientIdentifier,
const QUrl &authorizationUrl,
const QUrl &accessTokenUrl,
QNetworkAccessManager *manager,
quint16 port = 0,
QObject *parent = nullptr);
virtual ~QOAuth2AuthorizationCodeFlow();
......
......@@ -52,27 +52,27 @@
QT_BEGIN_NAMESPACE
QOAuth2ImplicitGrantFlowPrivate::QOAuth2ImplicitGrantFlowPrivate(QNetworkAccessManager *manager)
: QAbstractOAuth2Private(manager, 0)
QOAuth2ImplicitGrantFlowPrivate::QOAuth2ImplicitGrantFlowPrivate(QNetworkAccessManager *manager) :
QAbstractOAuth2Private(manager)
{}
QOAuth2ImplicitGrantFlowPrivate::~QOAuth2ImplicitGrantFlowPrivate()
{}
QOAuth2ImplicitGrantFlow::QOAuth2ImplicitGrantFlow(QObject *parent)
: QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(nullptr), parent)
QOAuth2ImplicitGrantFlow::QOAuth2ImplicitGrantFlow(QObject *parent) :
QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(nullptr), parent)
{}
QOAuth2ImplicitGrantFlow::QOAuth2ImplicitGrantFlow(QNetworkAccessManager *manager,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(manager), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(manager), parent)
{
}
QOAuth2ImplicitGrantFlow::QOAuth2ImplicitGrantFlow(const QString &clientIdentifier,
QNetworkAccessManager *manager,
QObject *parent)
: QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(manager), parent)
QObject *parent) :
QAbstractOAuth2(*new QOAuth2ImplicitGrantFlowPrivate(manager), parent)
{
Q_D(QOAuth2ImplicitGrantFlow);
d->clientCredentials.first = clientIdentifier;
......
......@@ -38,6 +38,7 @@
****************************************************************************/
#include <QtOAuth/qoauth2authorizationcodeflow.h>
#include <QtOAuth/qoauthhttpserverreplyhandler.h>
#include <QtCore>
#include <QtNetwork>
......@@ -92,7 +93,10 @@ int main(int argc, char **argv)
parser.showHelp();
QNetworkAccessManager manager;
QOAuth2AuthorizationCodeFlow o2(&manager, QUrl(clientInfo[redirectUriString]).port());
QOAuth2AuthorizationCodeFlow o2(&manager);
const QUrl redirectUri(clientInfo[redirectUriString]);
auto replyHandler = new QOAuthHttpServerReplyHandler(redirectUri.port(), &o2);
o2.setReplyHandler(replyHandler);
o2.setClientIdentifier(clientInfo[clientIdString]);
o2.setAuthorizationUrl(clientInfo[authUriString]);
o2.setAccessTokenUrl(clientInfo[tokenUriString]);
......
......@@ -41,6 +41,7 @@
#include <QtGui>
#include <QtCore>
#include <QtOAuth/qoauthhttpserverreplyhandler.h>
const QUrl newUrl("https://oauth.reddit.com/new");
const QUrl hotUrl("https://oauth.reddit.com/hot");
......@@ -49,7 +50,8 @@ const QUrl liveThreadsUrl("https://oauth.reddit.com/live/XXXX/about.json");
RedditWrapper::RedditWrapper(QObject *parent)
: QObject(parent)
{
oauth2.setPort(1337);
auto replyHandler = new QOAuthHttpServerReplyHandler(1337, this);
oauth2.setReplyHandler(replyHandler);
oauth2.setAuthorizationUrl(QUrl("https://www.reddit.com/api/v1/authorize"));
oauth2.setAccessTokenUrl(QUrl("https://www.reddit.com/api/v1/access_token"));
oauth2.setScope("identity read");
......
......@@ -47,12 +47,38 @@
#include <QtNetwork/qnetworkreply.h>
#include <QtOAuth/qoauth2authorizationcodeflow.h>
#include <QtOAuth/qoauthhttpserverreplyhandler.h>
QT_BEGIN_NAMESPACE
class QQmlOAuth2 : public QOAuth2AuthorizationCodeFlow
{
Q_OBJECT
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
QScopedPointer<QOAuthHttpServerReplyHandler> httpReplyHandler;
public:
QQmlOAuth2(QObject *parent = nullptr) :
QOAuth2AuthorizationCodeFlow(parent)
{
httpReplyHandler.reset(new QOAuthHttpServerReplyHandler);
}
int port() const
{
return httpReplyHandler->port();
}
void setPort(int port)
{
if (port != httpReplyHandler->port()) {
httpReplyHandler.reset(new QOAuthHttpServerReplyHandler(port));
setReplyHandler(httpReplyHandler.data());
Q_EMIT portChanged(port);
}
}
virtual void grant() override
{
if (!networkAccessManager()) {
......@@ -62,6 +88,9 @@ public:
Q_ASSERT(networkAccessManager() == qmlEngine(this)->networkAccessManager());
QOAuth2AuthorizationCodeFlow::grant();
}
Q_SIGNALS:
void portChanged(int port);
};
class QtOAuthPlugin : public QQmlExtensionPlugin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment