Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly encode scope and prompt items in OAuth URL #11479

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/11472
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Properly encode scope and prompt items in OAuth URL

Fixed a bug where the scope and prompt items of an OAuth query would not
be encoded, resulting in an invalid request.

https://github.com/owncloud/client/issues/11472
https://github.com/owncloud/client/pull/11479
5 changes: 0 additions & 5 deletions src/gui/creds/httpcredentialsgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ void HttpCredentialsGui::restartOAuth()
tr("The account %1 is currently logged out.\n\nPlease authenticate using your browser.").arg(_account->displayName()));

auto *contentWidget = qobject_cast<OAuthLoginWidget *>(_loginRequiredDialog->contentWidget());
connect(contentWidget, &OAuthLoginWidget::copyUrlToClipboardButtonClicked, _loginRequiredDialog, [](const QUrl &url) {
// TODO: use authorisationLinkAsync
qApp->clipboard()->setText(url.toString());
});

connect(contentWidget, &OAuthLoginWidget::openBrowserButtonClicked, this, &HttpCredentialsGui::openBrowser);
connect(_loginRequiredDialog, &LoginRequiredDialog::rejected, this, &HttpCredentials::requestLogout);

Expand Down
2 changes: 1 addition & 1 deletion src/gui/loginrequireddialog/oauthloginwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ OAuthLoginWidget::OAuthLoginWidget(QWidget *parent)
});
connect(_ui->copyUrlToClipboardButton, &QPushButton::clicked, this, [this] {
Q_ASSERT(_url.isValid());
Q_EMIT copyUrlToClipboardButtonClicked(_url);
qApp->clipboard()->setText(_url.toString(QUrl::FullyEncoded));
});

// depending on the theme we have to use a light or dark icon
Expand Down
1 change: 0 additions & 1 deletion src/gui/loginrequireddialog/oauthloginwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class OAuthLoginWidget : public AbstractLoginWidget

Q_SIGNALS:
void openBrowserButtonClicked(const QUrl &url);
void copyUrlToClipboardButtonClicked(const QUrl &url);

private:
::Ui::OAuthLoginWidget *_ui;
Expand Down
2 changes: 0 additions & 2 deletions src/gui/newwizard/pages/oauthcredentialssetupwizardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ OAuthCredentialsSetupWizardPage::OAuthCredentialsSetupWizardPage(const QUrl &ser
// TODO: move to OAuthLoginWidget
_ui->oauthLoginWidget->setOpenBrowserButtonText(tr("Reopen Browser"));
});
connect(
_ui->oauthLoginWidget, &OAuthLoginWidget::copyUrlToClipboardButtonClicked, this, [](const QUrl &url) { qApp->clipboard()->setText(url.toString()); });
connect(this, &AbstractSetupWizardPage::pageDisplayed, _ui->oauthLoginWidget, qOverload<>(&OAuthLoginWidget::setFocus));

_ui->topLabel->setText(tr("Please use your browser to log in to %1.").arg(Theme::instance()->appNameGUI()));
Expand Down
19 changes: 8 additions & 11 deletions src/libsync/creds/oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,8 @@ QNetworkReply *OAuth::postTokenRequest(const QList<QPair<QString, QString>> &que
req.setAttribute(HttpCredentials::DontAddCredentialsAttribute, true);

QUrlQuery arguments;
arguments.setQueryItems(QList<QPair<QString, QString>> { { QStringLiteral("client_id"), _clientId },
{ QStringLiteral("client_secret"), _clientSecret },
{ QStringLiteral("scope"), Theme::instance()->openIdConnectScopes() } }
arguments.setQueryItems(QList<QPair<QString, QString>>{{QStringLiteral("client_id"), _clientId}, {QStringLiteral("client_secret"), _clientSecret},
{QStringLiteral("scope"), QString::fromUtf8(QUrl::toPercentEncoding(Theme::instance()->openIdConnectScopes()))}}
<< queryItems);
req.setUrl(requestTokenUrl);
return _networkAccessManager->post(req, arguments.toString(QUrl::FullyEncoded).toUtf8());
Expand All @@ -443,14 +442,12 @@ QUrl OAuth::authorisationLink() const

const QByteArray code_challenge = QCryptographicHash::hash(_pkceCodeVerifier, QCryptographicHash::Sha256)
.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
QUrlQuery query { { QStringLiteral("response_type"), QStringLiteral("code") },
{ QStringLiteral("client_id"), _clientId },
{ QStringLiteral("redirect_uri"), QStringLiteral("%1:%2").arg(_redirectUrl, QString::number(_server.serverPort())) },
{ QStringLiteral("code_challenge"), QString::fromLatin1(code_challenge) },
{ QStringLiteral("code_challenge_method"), QStringLiteral("S256") },
{ QStringLiteral("scope"), Theme::instance()->openIdConnectScopes() },
{ QStringLiteral("prompt"), Theme::instance()->openIdConnectPrompt() },
{ QStringLiteral("state"), QString::fromUtf8(_state) } };
QUrlQuery query{{QStringLiteral("response_type"), QStringLiteral("code")}, {QStringLiteral("client_id"), _clientId},
{QStringLiteral("redirect_uri"), QStringLiteral("%1:%2").arg(_redirectUrl, QString::number(_server.serverPort()))},
{QStringLiteral("code_challenge"), QString::fromLatin1(code_challenge)}, {QStringLiteral("code_challenge_method"), QStringLiteral("S256")},
{QStringLiteral("scope"), QString::fromUtf8(QUrl::toPercentEncoding(Theme::instance()->openIdConnectScopes()))},
{QStringLiteral("prompt"), QString::fromUtf8(QUrl::toPercentEncoding(Theme::instance()->openIdConnectPrompt()))},
{QStringLiteral("state"), QString::fromUtf8(_state)}};

if (!_davUser.isEmpty()) {
const QString davUser = QString::fromUtf8(QUrl::toPercentEncoding(_davUser)); // Issue #7762;
Expand Down
Loading