Commit 034b35a3 authored by Mårten Nordheim's avatar Mårten Nordheim Committed by Marten Nordheim
Browse files

Let the users change the path for the callback-url


Task-number: QTBUG-59653
Change-Id: I4bf938db2db3624c37b7f1a8d598bfa43052e2e0
Reviewed-by: default avatarTimur Pocheptsov <timur.pocheptsov@qt.io>
Showing with 25 additions and 2 deletions
......@@ -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"));
......
......@@ -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);
......
......@@ -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);
......
......@@ -63,6 +63,7 @@ public:
QTcpServer httpServer;
QString text;
QHostAddress listenAddress = QHostAddress::LocalHost;
QString path;
private:
void _q_clientConnected();
......
Supports Markdown
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