summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/oauth/twittertimeline/twitter.cpp1
-rw-r--r--src/oauth/qoauthhttpserverreplyhandler.cpp22
-rw-r--r--src/oauth/qoauthhttpserverreplyhandler.h3
-rw-r--r--src/oauth/qoauthhttpserverreplyhandler_p.h1
4 files changed, 25 insertions, 2 deletions
diff --git a/examples/oauth/twittertimeline/twitter.cpp b/examples/oauth/twittertimeline/twitter.cpp
index 49061a7..933ae3e 100644
--- a/examples/oauth/twittertimeline/twitter.cpp
+++ b/examples/oauth/twittertimeline/twitter.cpp
@@ -47,6 +47,7 @@ Twitter::Twitter(const QString &screenName,
QOAuth1(clientCredentials.first, clientCredentials.second, nullptr, parent)
{
replyHandler = new QOAuthHttpServerReplyHandler(this);
+ replyHandler->setCallbackPath("callback");
setReplyHandler(replyHandler);
setTemporaryCredentialsUrl(QUrl("https://api.twitter.com/oauth/request_token"));
setAuthorizationUrl(QUrl("https://api.twitter.com/oauth/authenticate"));
diff --git a/src/oauth/qoauthhttpserverreplyhandler.cpp b/src/oauth/qoauthhttpserverreplyhandler.cpp
index 3e3fdf6..c39f051 100644
--- a/src/oauth/qoauthhttpserverreplyhandler.cpp
+++ b/src/oauth/qoauthhttpserverreplyhandler.cpp
@@ -107,7 +107,7 @@ void QOAuthHttpServerReplyHandlerPrivate::_q_readData(QTcpSocket *socket)
void QOAuthHttpServerReplyHandlerPrivate::_q_answerClient(QTcpSocket *socket, const QUrl &url)
{
Q_Q(QOAuthHttpServerReplyHandler);
- if (!url.path().startsWith(QStringLiteral("/cb"))) {
+ if (!url.path().startsWith(QLatin1String("/") + path)) {
qWarning("QOAuthHttpServerReplyHandlerPrivate::_q_answerClient: Invalid request: %s",
qPrintable(url.toString()));
} else {
@@ -274,10 +274,28 @@ QString QOAuthHttpServerReplyHandler::callback() const
Q_D(const QOAuthHttpServerReplyHandler);
Q_ASSERT(d->httpServer.isListening());
- const QUrl url(QString::fromLatin1("http://localhost:%1/cb").arg(d->httpServer.serverPort()));
+ const QUrl url(QString::fromLatin1("http://localhost:%1/%2")
+ .arg(d->httpServer.serverPort()).arg(d->path));
return url.toString(QUrl::EncodeDelimiters);
}
+QString QOAuthHttpServerReplyHandler::callbackPath() const
+{
+ Q_D(const QOAuthHttpServerReplyHandler);
+ return d->path;
+}
+
+void QOAuthHttpServerReplyHandler::setCallbackPath(const QString &path)
+{
+ Q_D(QOAuthHttpServerReplyHandler);
+
+ QString copy = path;
+ while (copy.startsWith('/'))
+ copy = copy.mid(1);
+
+ d->path = copy;
+}
+
QString QOAuthHttpServerReplyHandler::callbackText() const
{
Q_D(const QOAuthHttpServerReplyHandler);
diff --git a/src/oauth/qoauthhttpserverreplyhandler.h b/src/oauth/qoauthhttpserverreplyhandler.h
index f93eb33..74a99b6 100644
--- a/src/oauth/qoauthhttpserverreplyhandler.h
+++ b/src/oauth/qoauthhttpserverreplyhandler.h
@@ -55,6 +55,9 @@ public:
QString callback() const override;
+ QString callbackPath() const;
+ void setCallbackPath(const QString &path);
+
QString callbackText() const;
void setCallbackText(const QString &text);
diff --git a/src/oauth/qoauthhttpserverreplyhandler_p.h b/src/oauth/qoauthhttpserverreplyhandler_p.h
index 9d666eb..71873fd 100644
--- a/src/oauth/qoauthhttpserverreplyhandler_p.h
+++ b/src/oauth/qoauthhttpserverreplyhandler_p.h
@@ -63,6 +63,7 @@ public:
QTcpServer httpServer;
QString text;
QHostAddress listenAddress = QHostAddress::LocalHost;
+ QString path;
private:
void _q_clientConnected();