Skip to content

Commit

Permalink
Add Webfinger support to new wizard
Browse files Browse the repository at this point in the history
This commit adds support Webfinger lookups in the wizard. This way,
enterprise customers who allow authorization against a variety of OpenID
Connect servers can set up a Webfinger server to have the client use the
right IdP.

The commit includes @TheOneRing's the Webfinger implementation from #9366.
  • Loading branch information
Fabian Müller committed Jul 29, 2022
1 parent e075cc0 commit 19e0244
Show file tree
Hide file tree
Showing 22 changed files with 626 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/gui/newwizard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ add_library(newwizard STATIC
pages/serverurlsetupwizardpage.h
pages/serverurlsetupwizardpage.cpp

pages/webfingersetupwizardpage.ui
pages/webfingersetupwizardpage.h
pages/webfingersetupwizardpage.cpp

pages/basiccredentialssetupwizardpage.ui
pages/basiccredentialssetupwizardpage.h
pages/basiccredentialssetupwizardpage.cpp
Expand Down Expand Up @@ -43,6 +47,7 @@ add_library(newwizard STATIC

states/abstractsetupwizardstate.cpp
states/serverurlsetupwizardstate.cpp
states/webfingersetupwizardstate.cpp
states/basiccredentialssetupwizardstate.cpp
states/oauthcredentialssetupwizardstate.cpp
states/accountconfiguredsetupwizardstate.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/gui/newwizard/enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ QString OCC::Utility::enumToDisplayName(SetupWizardState state)
switch (state) {
case SetupWizardState::ServerUrlState:
return QApplication::translate(contextC, "Server URL");
case SetupWizardState::WebFingerState:
return QApplication::translate(contextC, "WebFinger");
case SetupWizardState::CredentialsState:
return QApplication::translate(contextC, "Credentials");
case SetupWizardState::AccountConfiguredState:
Expand Down
2 changes: 2 additions & 0 deletions src/gui/newwizard/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enum class SetupWizardState {
ServerUrlState,
FirstState = ServerUrlState,

WebFingerState,

CredentialsState,

AccountConfiguredState,
Expand Down
8 changes: 8 additions & 0 deletions src/gui/newwizard/pages/basiccredentialssetupwizardpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ BasicCredentialsSetupWizardPage::BasicCredentialsSetupWizardPage(const QUrl &ser
_ui->appPasswordLabel->setText(tr("Click <a href='%1' style='color: %2;'>here</a> to set up an app password.").arg(appPasswordUrl, linkColor));
}

BasicCredentialsSetupWizardPage *BasicCredentialsSetupWizardPage::createForWebFinger(const QUrl &serverUrl, const QString &username)
{
auto page = new BasicCredentialsSetupWizardPage(serverUrl);
page->_ui->usernameLineEdit->setText(username);
page->_ui->usernameLineEdit->setEnabled(false);
return page;
}

QString BasicCredentialsSetupWizardPage::username() const
{
return _ui->usernameLineEdit->text();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/newwizard/pages/basiccredentialssetupwizardpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class BasicCredentialsSetupWizardPage : public AbstractSetupWizardPage
BasicCredentialsSetupWizardPage(const QUrl &serverUrl);
~BasicCredentialsSetupWizardPage() noexcept override;

static BasicCredentialsSetupWizardPage *createForWebFinger(const QUrl &serverUrl, const QString &username);

QString username() const;
QString password() const;

Expand Down
54 changes: 54 additions & 0 deletions src/gui/newwizard/pages/webfingersetupwizardpage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) Fabian Müller <fmueller@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "webfingersetupwizardpage.h"
#include "ui_webfingersetupwizardpage.h"

#include "theme.h"

namespace OCC::Wizard {

WebFingerSetupWizardPage::WebFingerSetupWizardPage(const QUrl &serverUrl)
: _ui(new ::Ui::WebFingerSetupWizardPage)
{
_ui->setupUi(this);

_ui->urlLabel->setText(tr("Connecting to <a href='%1' style='color: %2;'>%1</a>").arg(serverUrl.toString(), Theme::instance()->wizardHeaderTitleColor().name()));

connect(this, &AbstractSetupWizardPage::pageDisplayed, this, [this]() {
_ui->usernameLineEdit->setFocus();
});

_ui->usernameLabel->setText(Utility::enumToDisplayName(Theme::instance()->userIDType()));

if (!Theme::instance()->userIDHint().isEmpty()) {
_ui->usernameLineEdit->setPlaceholderText(Theme::instance()->userIDHint());
}
}

QString WebFingerSetupWizardPage::username() const
{
return _ui->usernameLineEdit->text();
}

WebFingerSetupWizardPage::~WebFingerSetupWizardPage()
{
delete _ui;
}

bool WebFingerSetupWizardPage::validateInput()
{
return !(username().isEmpty());
}
}
41 changes: 41 additions & 0 deletions src/gui/newwizard/pages/webfingersetupwizardpage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) Fabian Müller <fmueller@owncloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#pragma once

#include "abstractsetupwizardpage.h"

namespace Ui {
class WebFingerSetupWizardPage;
}

namespace OCC::Wizard {

class WebFingerSetupWizardPage : public AbstractSetupWizardPage
{
Q_OBJECT

public:
WebFingerSetupWizardPage(const QUrl &serverUrl);
~WebFingerSetupWizardPage() noexcept override;

QString username() const;

bool validateInput() override;

private:
::Ui::WebFingerSetupWizardPage *_ui;
};

}
140 changes: 140 additions & 0 deletions src/gui/newwizard/pages/webfingersetupwizardpage.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WebFingerSetupWizardPage</class>
<widget class="QWidget" name="WebFingerSetupWizardPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>629</width>
<height>434</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="enterYourUsernameLabel">
<property name="text">
<string>Please enter your username:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="usernameLabel">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="usernameLineEdit">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="placeholderText">
<string>Username</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="urlLabel">
<property name="text">
<string notr="true">&lt;server URL&gt; (placeholder)</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
20 changes: 20 additions & 0 deletions src/gui/newwizard/setupwizardaccountbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ DetermineAuthTypeJob::AuthType SetupWizardAccountBuilder::authType()
return _authType;
}

void SetupWizardAccountBuilder::setWebFingerUsername(const QString &username)
{
_webFingerUsername = username;
}

AccountPtr SetupWizardAccountBuilder::build()
{
auto newAccountPtr = Account::create();
Expand Down Expand Up @@ -163,4 +168,19 @@ void SetupWizardAccountBuilder::setDefaultSyncTargetDir(const QString &syncTarge
{
_defaultSyncTargetDir = syncTargetDir;
}

QString SetupWizardAccountBuilder::webFingerUsername() const
{
return _webFingerUsername;
}

void SetupWizardAccountBuilder::setWebFingerServerUrl(const QUrl &webFingerServerUrl)
{
_webFingerServerUrl = webFingerServerUrl;
}

QUrl SetupWizardAccountBuilder::webFingerServerUrl() const
{
return _webFingerServerUrl;
}
}
23 changes: 21 additions & 2 deletions src/gui/newwizard/setupwizardaccountbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,28 @@ class SetupWizardAccountBuilder
SetupWizardAccountBuilder();

/**
* Set server URL.
* Set ownCloud server URL as well as the authentication type that needs to be used with this server.
* @param serverUrl URL to server
*/
void setServerUrl(const QUrl &serverUrl, DetermineAuthTypeJob::AuthType workflowType);
QUrl serverUrl() const;

/**
* Set URL of WebFinger server used to look up the user's server.
* Only used when WebFinger support is enabled by the theme.
* @param webFingerServerUrl URL to WebFinger server
*/
void setWebFingerServerUrl(const QUrl &webFingerServerUrl);
QUrl webFingerServerUrl() const;

/**
* Set URL of WebFinger server used to look up the user's server.
* Only used when WebFinger support is enabled by the theme.
* @param username
*/
void setWebFingerUsername(const QString &username);
QString webFingerUsername() const;

// TODO: move this out of the class's state
DetermineAuthTypeJob::AuthType authType();

Expand Down Expand Up @@ -142,12 +158,15 @@ class SetupWizardAccountBuilder
private:
QUrl _serverUrl;

QString _displayName;
QString _webFingerUsername;
QUrl _webFingerServerUrl;

DetermineAuthTypeJob::AuthType _authType = DetermineAuthTypeJob::AuthType::Unknown;

std::unique_ptr<AbstractAuthenticationStrategy> _authenticationStrategy;

QString _displayName;

QSet<QSslCertificate> _customTrustedCaCertificates;

QString _defaultSyncTargetDir;
Expand Down
Loading

0 comments on commit 19e0244

Please sign in to comment.