Ensure that the users id is used for accessing webdav

https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/index.html#obtaining-the-login-credentials
states that the email address can be used for login but it's not
allowed to use the email address to access webdav.

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
This commit is contained in:
Felix Weilbach 2021-08-06 11:34:49 +02:00
parent f932638054
commit 5195264a20
3 changed files with 28 additions and 15 deletions

View file

@ -16,12 +16,18 @@
#include "common/utility.h" #include "common/utility.h"
#include "account.h" #include "account.h"
#include "creds/webflowcredentials.h"
#include "networkjobs.h"
#include "wizard/owncloudwizardcommon.h" #include "wizard/owncloudwizardcommon.h"
#include "theme.h" #include "theme.h"
#include "linklabel.h" #include "linklabel.h"
#include "QProgressIndicator.h" #include "QProgressIndicator.h"
#include <QJsonDocument>
#include <QStringLiteral>
#include <QJsonObject>
namespace OCC { namespace OCC {
Q_LOGGING_CATEGORY(lcFlow2AuthWidget, "nextcloud.gui.wizard.flow2authwidget", QtInfoMsg) Q_LOGGING_CATEGORY(lcFlow2AuthWidget, "nextcloud.gui.wizard.flow2authwidget", QtInfoMsg)
@ -102,7 +108,25 @@ void Flow2AuthWidget::slotAuthResult(Flow2Auth::Result r, const QString &errorSt
} }
} }
_account->setCredentials(new WebFlowCredentials(user, appPassword));
const auto fetchUserNameJob = new JsonApiJob(_account->sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user"));
connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, fetchUserNameJob, r, errorString, user, appPassword](const QJsonDocument &json, int statusCode) {
fetchUserNameJob->deleteLater();
if (statusCode != 100) {
qCWarning(lcFlow2AuthWidget) << "Could not fetch username";
_account->setDavDisplayName(user);
emit authResult(r, errorString, user, appPassword); emit authResult(r, errorString, user, appPassword);
return;
}
const auto objData = json.object().value("ocs").toObject().value("data").toObject();
const auto userId = objData.value("id").toString(user);
const auto displayName = objData.value("display-name").toString();
_account->setDavDisplayName(displayName);
emit authResult(r, errorString, userId, appPassword);
});
fetchUserNameJob->start();
} }
void Flow2AuthWidget::setError(const QString &error) { void Flow2AuthWidget::setError(const QString &error) {

View file

@ -168,7 +168,7 @@ void OwncloudAdvancedSetupPage::initializePage()
_ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage()); _ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage());
fetchUserAvatar(); fetchUserAvatar();
fetchUserData(); setUserInformation();
customizeStyle(); customizeStyle();
@ -201,20 +201,9 @@ void OwncloudAdvancedSetupPage::fetchUserAvatar()
avatarJob->start(); avatarJob->start();
} }
void OwncloudAdvancedSetupPage::fetchUserData() void OwncloudAdvancedSetupPage::setUserInformation()
{ {
const auto account = _ocWizard->account(); const auto account = _ocWizard->account();
// Fetch user data
const auto userJob = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/user"), this);
userJob->setTimeout(20 * 1000);
connect(userJob, &JsonApiJob::jsonReceived, this, [this](const QJsonDocument &json) {
const auto objData = json.object().value("ocs").toObject().value("data").toObject();
const auto displayName = objData.value("display-name").toString();
_ui.userNameLabel->setText(displayName);
});
userJob->start();
const auto serverUrl = account->url().toString(); const auto serverUrl = account->url().toString();
setServerAddressLabelUrl(serverUrl); setServerAddressLabelUrl(serverUrl);
const auto userName = account->davDisplayName(); const auto userName = account->davDisplayName();

View file

@ -82,7 +82,7 @@ private:
void setResolutionGuiVisible(bool value); void setResolutionGuiVisible(bool value);
void setupResoultionWidget(); void setupResoultionWidget();
void fetchUserAvatar(); void fetchUserAvatar();
void fetchUserData(); void setUserInformation();
// TODO: remove when UX decision is made // TODO: remove when UX decision is made
void refreshVirtualFilesAvailibility(const QString &path); void refreshVirtualFilesAvailibility(const QString &path);