OAuth2: Fix double slash in URL
authorOlivier Goffart <ogoffart@woboq.com>
Fri, 22 Sep 2017 16:05:47 +0000 (18:05 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:36 +0000 (22:01 +0200)
We need to use concatPath to avoid possible double '/' in the URLs if the
account url() ends with '/'.

This has become even more of a problem since commit
d1b8370a4ad21c741da507f64a5dbfe82a3fad05 which was resolving the url after
a redirect where most server actually add a '/' if the url is a folder

src/gui/creds/oauth.cpp
src/libsync/creds/httpcredentials.cpp

index 0155b081042dfcc9704039fb5f606359e1bcc14c..05ef093b3e4e3832c3dc185dc536f6307022a5c7 100644 (file)
@@ -76,7 +76,7 @@ void OAuth::start()
 
                 QString code = rx.cap(1); // The 'code' is the first capture of the regexp
 
-                QUrl requestToken(_account->url().toString() + QLatin1String("/index.php/apps/oauth2/api/v1/token"));
+                QUrl requestToken = Utility::concatUrlPath(_account->url().toString(), QLatin1String("/index.php/apps/oauth2/api/v1/token"));
                 QNetworkRequest req;
                 req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
 
@@ -154,10 +154,10 @@ void OAuth::start()
 QUrl OAuth::authorisationLink() const
 {
     Q_ASSERT(_server.isListening());
-    QUrl url = QUrl(_account->url().toString()
-        + QLatin1String("/index.php/apps/oauth2/authorize?response_type=code&client_id=")
-        + Theme::instance()->oauthClientId()
-        + QLatin1String("&redirect_uri=http://localhost:") + QString::number(_server.serverPort()));
+    QUrl url = Utility::concatUrlPath(_account->url(), QLatin1String("/index.php/apps/oauth2/authorize"),
+        { { QLatin1String("response_type"), QLatin1String("code") },
+            { QLatin1String("client_id"), Theme::instance()->oauthClientId() },
+            { QLatin1String("redirect_uri"), QLatin1String("http://localhost:") + QString::number(_server.serverPort()) } });
     if (!_expectedUser.isNull())
         url.addQueryItem("user", _expectedUser);
     return url;
index 52e96edf3f9f4b6fbf6022d9dac9b8ee08220459..771008bf627bb2c8c3d07a84126f861e0eadf7f3 100644 (file)
@@ -344,7 +344,7 @@ bool HttpCredentials::refreshAccessToken()
     if (_refreshToken.isEmpty())
         return false;
 
-    QUrl requestToken(_account->url().toString() + QLatin1String("/index.php/apps/oauth2/api/v1/token"));
+    QUrl requestToken = Utility::concatUrlPath(_account->url(), QLatin1String("/index.php/apps/oauth2/api/v1/token"));
     QNetworkRequest req;
     req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");