OAuth2: Store 'Account::davUser' in the config, and use that user for connecting

We need to use the user id to check if we are connected to the right account.
These might be different from the HTTP Basic Auth login. (LDAP setups)

When the account was configured as an oauth2 account form the wisard, the
http_user was already set correctly to the user id. But when the server is
upgrading from basic auth to oauth2, we need to pick the right login.

Note that Account::davUser() already defaults to the HTTP user when none
is set, so this means the upgrade will be fine if this is not set in the
config.

Issues:
https://github.com/owncloud/oauth2/issues/109
https://github.com/owncloud/enterprise/issues/2781
This commit is contained in:
Olivier Goffart 2018-10-05 19:45:43 +02:00 committed by Kevin Ottens
parent 75f66ddaa1
commit 15eab07866
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
3 changed files with 7 additions and 1 deletions

View file

@ -32,6 +32,7 @@ static const char urlC[] = "url";
static const char authTypeC[] = "authType";
static const char userC[] = "user";
static const char httpUserC[] = "http_user";
static const char davUserC[] = "dav_user";
static const char caCertsKeyC[] = "CaCertificates";
static const char accountsC[] = "Accounts";
static const char versionC[] = "version";
@ -215,6 +216,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
{
settings.setValue(QLatin1String(versionC), maxAccountVersion);
settings.setValue(QLatin1String(urlC), acc->_url.toString());
settings.setValue(QLatin1String(davUserC), acc->_davUser);
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);
if (acc->_credentials) {
if (saveCredentials) {
@ -307,6 +309,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
qCInfo(lcAccountManager) << "Account for" << acc->url() << "using auth type" << authType;
acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString();
acc->_davUser = settings.value(QLatin1String(davUserC)).toString();
// We want to only restore settings for that auth type and the user value
acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));

View file

@ -48,7 +48,7 @@ void HttpCredentialsGui::askFromUserAsync()
QObject::connect(job, &DetermineAuthTypeJob::authType, this, [this](DetermineAuthTypeJob::AuthType type) {
if (type == DetermineAuthTypeJob::OAuth) {
_asyncAuth.reset(new OAuth(_account, this));
_asyncAuth->_expectedUser = _user;
_asyncAuth->_expectedUser = _account->davUser();
connect(_asyncAuth.data(), &OAuth::result,
this, &HttpCredentialsGui::asyncAuthResult);
connect(_asyncAuth.data(), &OAuth::destroyed,

View file

@ -111,7 +111,10 @@ QString Account::davUser() const
void Account::setDavUser(const QString &newDavUser)
{
if (_davUser == newDavUser)
return;
_davUser = newDavUser;
emit wantsAccountSaved(this);
}
#ifndef TOKEN_AUTH_ONLY