Skip to content

Commit

Permalink
Merge pull request #6075 from nextcloud/bugfix/remove-dead-uauth-code…
Browse files Browse the repository at this point in the history
…-3.10

[stable-3.10] Bugfix/remove dead oauth code
  • Loading branch information
claucambra authored Sep 19, 2023
2 parents 295f22e + 498316c commit 61cba1e
Show file tree
Hide file tree
Showing 26 changed files with 30 additions and 1,167 deletions.
5 changes: 0 additions & 5 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ set(client_UI_SRCS
wizard/owncloudadvancedsetuppage.ui
wizard/owncloudconnectionmethoddialog.ui
wizard/owncloudhttpcredspage.ui
wizard/owncloudoauthcredspage.ui
wizard/owncloudsetupnocredspage.ui
wizard/webview.ui
wizard/welcomepage.ui
Expand Down Expand Up @@ -225,8 +224,6 @@ set(client_SRCS
creds/credentialsfactory.cpp
creds/httpcredentialsgui.h
creds/httpcredentialsgui.cpp
creds/oauth.h
creds/oauth.cpp
creds/flow2auth.h
creds/flow2auth.cpp
creds/webflowcredentials.h
Expand All @@ -243,8 +240,6 @@ set(client_SRCS
wizard/owncloudconnectionmethoddialog.cpp
wizard/owncloudhttpcredspage.h
wizard/owncloudhttpcredspage.cpp
wizard/owncloudoauthcredspage.h
wizard/owncloudoauthcredspage.cpp
wizard/flow2authcredspage.h
wizard/flow2authcredspage.cpp
wizard/flow2authwidget.h
Expand Down
14 changes: 1 addition & 13 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1271,19 +1271,7 @@ void AccountSettings::slotAccountStateChanged()
showConnectionLabel(tr("Signed out from %1.").arg(serverWithUser));
break;
case AccountState::AskingCredentials: {
QUrl url;
if (const auto cred = qobject_cast<HttpCredentialsGui *>(account->credentials())) {
connect(cred, &HttpCredentialsGui::authorisationLinkChanged,
this, &AccountSettings::slotAccountStateChanged, Qt::UniqueConnection);
url = cred->authorisationLink();
}
if (url.isValid()) {
showConnectionLabel(tr("Obtaining authorization from the browser. "
"<a href='%1'>Click here</a> to re-open the browser.")
.arg(url.toString(QUrl::FullyEncoded)));
} else {
showConnectionLabel(tr("Connecting to %1 …").arg(serverWithUser));
}
showConnectionLabel(tr("Connecting to %1 …").arg(serverWithUser));
break;
}
case AccountState::NetworkError:
Expand Down
4 changes: 0 additions & 4 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,6 @@ void AccountState::handleInvalidCredentials()
if (account()->credentials()->ready()) {
account()->credentials()->invalidateToken();
}
if (auto creds = qobject_cast<HttpCredentials *>(account()->credentials())) {
if (creds->refreshAccessToken())
return;
}
account()->credentials()->askFromUser();
}

Expand Down
38 changes: 1 addition & 37 deletions src/gui/creds/httpcredentialsgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ void HttpCredentialsGui::askFromUserAsync()
// First, we will check what kind of auth we need.
auto job = new DetermineAuthTypeJob(_account->sharedFromThis(), this);
QObject::connect(job, &DetermineAuthTypeJob::authType, this, [this](DetermineAuthTypeJob::AuthType type) {
if (type == DetermineAuthTypeJob::OAuth) {
_asyncAuth.reset(new OAuth(_account, this));
_asyncAuth->_expectedUser = _account->davUser();
connect(_asyncAuth.data(), &OAuth::result,
this, &HttpCredentialsGui::asyncAuthResult);
connect(_asyncAuth.data(), &OAuth::destroyed,
this, &HttpCredentialsGui::authorisationLinkChanged);
_asyncAuth->start();
emit authorisationLinkChanged();
} else if (type == DetermineAuthTypeJob::Basic) {
if (type == DetermineAuthTypeJob::Basic) {
showDialog();
} else {
// Shibboleth?
Expand All @@ -66,32 +57,6 @@ void HttpCredentialsGui::askFromUserAsync()
job->start();
}

void HttpCredentialsGui::asyncAuthResult(OAuth::Result r, const QString &user,
const QString &token, const QString &refreshToken)
{
switch (r) {
case OAuth::NotSupported:
showDialog();
_asyncAuth.reset(nullptr);
return;
case OAuth::Error:
_asyncAuth.reset(nullptr);
emit asked();
return;
case OAuth::LoggedIn:
break;
}

ASSERT(_user == user); // ensured by _asyncAuth

_password = token;
_refreshToken = refreshToken;
_ready = true;
persist();
_asyncAuth.reset(nullptr);
emit asked();
}

void HttpCredentialsGui::showDialog()
{
QString msg = tr("Please enter %1 password:<br>"
Expand Down Expand Up @@ -128,7 +93,6 @@ void HttpCredentialsGui::showDialog()
connect(dialog, &QDialog::finished, this, [this, dialog](int result) {
if (result == QDialog::Accepted) {
_password = dialog->textValue();
_refreshToken.clear();
_ready = true;
persist();
}
Expand Down
25 changes: 0 additions & 25 deletions src/gui/creds/httpcredentialsgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#pragma once
#include "creds/httpcredentials.h"
#include "creds/oauth.h"
#include <QPointer>
#include <QTcpServer>

Expand All @@ -38,37 +37,13 @@ class HttpCredentialsGui : public HttpCredentials
: HttpCredentials(user, password, clientCertBundle, clientCertPassword)
{
}
HttpCredentialsGui(const QString &user, const QString &password, const QString &refreshToken,
const QByteArray &clientCertBundle, const QByteArray &clientCertPassword)
: HttpCredentials(user, password, clientCertBundle, clientCertPassword)
{
_refreshToken = refreshToken;
}

/**
* This will query the server and either uses OAuth via _asyncAuth->start()
* or call showDialog to ask the password
*/
void askFromUser() override;
/**
* In case of oauth, return an URL to the link to open the browser.
* An invalid URL otherwise
*/
[[nodiscard]] QUrl authorisationLink() const { return _asyncAuth ? _asyncAuth->authorisationLink() : QUrl(); }


static QString requestAppPasswordText(const Account *account);
private slots:
void asyncAuthResult(OAuth::Result, const QString &user, const QString &accessToken, const QString &refreshToken);
void showDialog();
void askFromUserAsync();

signals:
void authorisationLinkChanged();

private:

QScopedPointer<OAuth, QScopedPointerObjectDeleteLater<OAuth>> _asyncAuth;
};

} // namespace OCC
187 changes: 0 additions & 187 deletions src/gui/creds/oauth.cpp

This file was deleted.

Loading

0 comments on commit 61cba1e

Please sign in to comment.