Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Müller <fmueller@owncloud.com>2022-06-16 02:36:15 +0300
committerFabian Müller <fmueller@owncloud.com>2022-07-05 18:15:54 +0300
commit31dda87ba19db9f11591fb5186a08960ed5b1a6f (patch)
tree8320091a77c8879d97ea7e8569ea8ada96f0c0f8
parentc7b4374df94d185739ec536557ae6a9e4cffc4c6 (diff)
Eliminate redundancy of authorisationLink* functionalitywork/copy-clipboard-oauth-accounts-page
-rw-r--r--src/gui/askforoauthlogindialog.cpp10
-rw-r--r--src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp6
-rw-r--r--src/gui/newwizard/pages/oauthcredentialssetupwizardpage.h2
-rw-r--r--src/gui/newwizard/states/oauthcredentialssetupwizardstate.cpp12
-rw-r--r--src/libsync/creds/oauth.cpp48
-rw-r--r--src/libsync/creds/oauth.h8
6 files changed, 49 insertions, 37 deletions
diff --git a/src/gui/askforoauthlogindialog.cpp b/src/gui/askforoauthlogindialog.cpp
index 1eaff71a3..48896ebe7 100644
--- a/src/gui/askforoauthlogindialog.cpp
+++ b/src/gui/askforoauthlogindialog.cpp
@@ -35,6 +35,16 @@ AskForOAuthLoginDialog::AskForOAuthLoginDialog(AccountPtr accountPtr, QWidget *p
setFixedSize(this->sizeHint());
+ auto creds = qobject_cast<HttpCredentialsGui *>(accountPtr->credentials());
+ Q_ASSERT(creds != nullptr);
+
+ _ui->copyUrlToClipboardButton->setEnabled(false);
+ _ui->openBrowserButton->setEnabled(false);
+ connect(creds, &HttpCredentialsGui::authorisationLinkChanged, this, [this]() {
+ _ui->copyUrlToClipboardButton->setEnabled(true);
+ _ui->openBrowserButton->setEnabled(true);
+ });
+
connect(_ui->openBrowserButton, &QPushButton::clicked, this, [this, accountPtr]() {
qobject_cast<HttpCredentialsGui *>(accountPtr->credentials())->openBrowser();
_ui->openBrowserButton->setText(tr("Reopen browser"));
diff --git a/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp b/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp
index 0eb4ae167..8d42f2c7f 100644
--- a/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp
+++ b/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp
@@ -64,4 +64,10 @@ bool OAuthCredentialsSetupWizardPage::validateInput()
return false;
}
+void OAuthCredentialsSetupWizardPage::setButtonsEnabled(bool enabled)
+{
+ _ui->copyUrlToClipboardButton->setEnabled(enabled);
+ _ui->openBrowserButton->setEnabled(enabled);
+}
+
} // namespace OCC::Wizard
diff --git a/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.h b/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.h
index 443dbe57d..13d310b6a 100644
--- a/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.h
+++ b/src/gui/newwizard/pages/oauthcredentialssetupwizardpage.h
@@ -33,6 +33,8 @@ public:
bool validateInput() override;
+ void setButtonsEnabled(bool enabled);
+
Q_SIGNALS:
void openBrowserButtonPushed();
void copyUrlToClipboardButtonPushed();
diff --git a/src/gui/newwizard/states/oauthcredentialssetupwizardstate.cpp b/src/gui/newwizard/states/oauthcredentialssetupwizardstate.cpp
index dc948847f..24e11e8af 100644
--- a/src/gui/newwizard/states/oauthcredentialssetupwizardstate.cpp
+++ b/src/gui/newwizard/states/oauthcredentialssetupwizardstate.cpp
@@ -15,6 +15,7 @@
#include <QApplication>
#include <QClipboard>
+#include "gui/application.h"
#include "oauthcredentialssetupwizardstate.h"
namespace OCC::Wizard {
@@ -60,10 +61,15 @@ OAuthCredentialsSetupWizardState::OAuthCredentialsSetupWizardState(SetupWizardCo
oAuth->openBrowser();
});
+ oAuthCredentialsPage->setButtonsEnabled(false);
+ connect(oAuth, &OAuth::authorisationLinkChanged, this, [oAuthCredentialsPage]() {
+ oAuthCredentialsPage->setButtonsEnabled(true);
+ });
+
connect(oAuthCredentialsPage, &OAuthCredentialsSetupWizardPage::copyUrlToClipboardButtonPushed, this, [oAuth]() {
- // TODO: use authorisationLinkAsync
- auto link = oAuth->authorisationLink().toString();
- QApplication::clipboard()->setText(link);
+ const auto link = oAuth->authorisationLink();
+ Q_ASSERT(!link.isEmpty());
+ ocApp()->clipboard()->setText(link.toString());
});
// moving to next page is only possible once we see a request to our embedded web server
diff --git a/src/libsync/creds/oauth.cpp b/src/libsync/creds/oauth.cpp
index 632146238..2788564fe 100644
--- a/src/libsync/creds/oauth.cpp
+++ b/src/libsync/creds/oauth.cpp
@@ -247,15 +247,15 @@ void OAuth::startAuthentication()
_clientId = clientId;
_clientSecret = clientSecret;
Q_EMIT dynamicRegistrationDataReceived(dynamicRegistrationData);
- Q_EMIT authorisationLinkChanged(authorisationLink());
+ Q_EMIT authorisationLinkChanged();
});
connect(job, &RegisterClientJob::errorOccured, this, [this](const QString &error) {
qCWarning(lcOauth) << "Failed to dynamically register the client, try the default client id" << error;
- Q_EMIT authorisationLinkChanged(authorisationLink());
+ Q_EMIT authorisationLinkChanged();
});
job->start();
} else {
- Q_EMIT authorisationLinkChanged(authorisationLink());
+ Q_EMIT authorisationLinkChanged();
}
});
fetchWellKnown();
@@ -476,6 +476,8 @@ QByteArray OAuth::generateRandomString(size_t size) const
QUrl OAuth::authorisationLink() const
{
Q_ASSERT(_server.isListening());
+ Q_ASSERT(_wellKnownFinished);
+
const QByteArray code_challenge = QCryptographicHash::hash(_pkceCodeVerifier, QCryptographicHash::Sha256)
.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
QUrlQuery query { { QStringLiteral("response_type"), QStringLiteral("code") },
@@ -497,16 +499,8 @@ QUrl OAuth::authorisationLink() const
const QUrl url = _authEndpoint.isValid()
? Utility::concatUrlPath(_authEndpoint, {}, query)
: Utility::concatUrlPath(_serverUrl, QStringLiteral("/index.php/apps/oauth2/authorize"), query);
- return url;
-}
-void OAuth::authorisationLinkAsync(std::function<void (const QUrl &)> callback) const
-{
- if (_wellKnownFinished) {
- callback(authorisationLink());
- } else {
- connect(this, &OAuth::authorisationLinkChanged, callback);
- }
+ return url;
}
void OAuth::fetchWellKnown()
@@ -573,22 +567,22 @@ bool isUrlValid(const QUrl &url)
void OAuth::openBrowser()
{
- authorisationLinkAsync([this](const QUrl &link) {
- if (!isUrlValid(link)) {
- qCWarning(lcOauth) << "URL validation failed";
- QMetaObject::invokeMethod(qApp, "slotShowGuiMessage", Qt::QueuedConnection,
- Q_ARG(QString, tr("Oauth2 Error")),
- Q_ARG(QString, tr("Oauth2 authentication requires a secured connection.")));
- emit result(Error, QString());
- return;
- }
+ Q_ASSERT(!authorisationLink().isEmpty());
+
+ if (!isUrlValid(authorisationLink())) {
+ qCWarning(lcOauth) << "URL validation failed";
+ QMetaObject::invokeMethod(qApp, "slotShowGuiMessage", Qt::QueuedConnection,
+ Q_ARG(QString, tr("Oauth2 Error")),
+ Q_ARG(QString, tr("Oauth2 authentication requires a secured connection.")));
+ emit result(Error, QString());
+ return;
+ }
- if (!QDesktopServices::openUrl(link)) {
- qCWarning(lcOauth) << "QDesktopServices::openUrl Failed";
- // We cannot open the browser, then we claim we don't support OAuth.
- emit result(NotSupported, QString());
- }
- });
+ if (!QDesktopServices::openUrl(authorisationLink())) {
+ qCWarning(lcOauth) << "QDesktopServices::openUrl Failed";
+ // We cannot open the browser, then we claim we don't support OAuth.
+ emit result(NotSupported, QString());
+ }
}
AccountBasedOAuth::AccountBasedOAuth(AccountPtr account, QObject *parent)
diff --git a/src/libsync/creds/oauth.h b/src/libsync/creds/oauth.h
index 6ccb9c645..632f9e17b 100644
--- a/src/libsync/creds/oauth.h
+++ b/src/libsync/creds/oauth.h
@@ -67,12 +67,6 @@ public:
void refreshAuthentication(const QString &refreshToken);
void openBrowser();
QUrl authorisationLink() const;
- /**
- * Call the callback when the call to the well-known endpoint finishes.
- * (or immediatly if it is ready)
- * The callback will not be called if this object gets destroyed
- */
- void authorisationLinkAsync(std::function<void(const QUrl&)> callback) const;
Q_SIGNALS:
/**
@@ -84,7 +78,7 @@ Q_SIGNALS:
/**
* emitted when the call to the well-known endpoint is finished
*/
- void authorisationLinkChanged(const QUrl &);
+ void authorisationLinkChanged();
void refreshError(QNetworkReply::NetworkError error, const QString &errorString);
void refreshFinished(const QString &accessToken, const QString &refreshToken);