Wizard + OAuth: Make opening a new browser after clicking back works again
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 18 Jun 2018 10:43:21 +0000 (12:43 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:55 +0000 (10:57 +0100)
Issue #6574

When there is an error in the advanced page, OwncloudAdvancedSetupPage::updateStatus
(and others) call completeChanged(), which is connected to
QWizardPrivate::_q_updateButtonStates which will re-enable the back button from the
last page.

When the user click "back" and re-open the browser, the account's credentials
already have a oauth token set. So the call to the API to get a new token fails
because we use the previous token instead of using the client's secret_id.
Fix this with the HttpCredentials::DontAddCredentialsAttribute.

Now, this is still not working because the session cookies are confusing the
server.  So we'll clear the cookies when re-opening the browser

src/gui/creds/oauth.cpp
src/gui/wizard/owncloudoauthcredspage.cpp

index fa040955fccf91b7c01d49a862b9539956ccc373..353384aa7797447acdac9c9e3184f60c65ee10f8 100644 (file)
@@ -22,6 +22,7 @@
 #include <QJsonDocument>
 #include "theme.h"
 #include "networkjobs.h"
+#include "creds/httpcredentials.h"
 
 namespace OCC {
 
@@ -83,6 +84,8 @@ void OAuth::start()
                 QString basicAuth = QString("%1:%2").arg(
                     Theme::instance()->oauthClientId(), Theme::instance()->oauthClientSecret());
                 req.setRawHeader("Authorization", "Basic " + basicAuth.toUtf8().toBase64());
+                // We just added the Authorization header, don't let HttpCredentialsAccessManager tamper with it
+                req.setAttribute(HttpCredentials::DontAddCredentialsAttribute, true);
 
                 auto requestBody = new QBuffer;
                 QUrlQuery arguments(QString(
index 9ed5da0d345f7f5153feda0452472d65a36a8701..79f36ba364af6cb88b23a4f0e915a9c7f5be96e6 100644 (file)
@@ -125,6 +125,8 @@ void OwncloudOAuthCredsPage::slotOpenBrowser()
     if (_ui.errorLabel)
         _ui.errorLabel->hide();
 
+    qobject_cast<OwncloudWizard *>(wizard())->account()->clearCookieJar(); // #6574
+
     if (_asyncAuth)
         _asyncAuth->openBrowser();
 }