diff --git a/CMakeLists.txt b/CMakeLists.txt index 713791db89c1b17973c07ef024dfafc3c53be576..0aec6d1c159e609440825a0ef21f2d5ff63b53f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" ${ECM_MODULE_P find_package(Intltool REQUIRED) find_package(KAccounts REQUIRED) -find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Qml WebEngineWidgets) +find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Qml WebEngineWidgets WebEngine) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED KIO I18n Declarative Package) include(KDEInstallDirs) diff --git a/plugins/nextcloud-ui/CMakeLists.txt b/plugins/nextcloud-ui/CMakeLists.txt index 88ffa0c6074edb55186fcb95d134ad62887bebf5..08319bc4def71ac6e284f30b89ce2511335915aa 100644 --- a/plugins/nextcloud-ui/CMakeLists.txt +++ b/plugins/nextcloud-ui/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(nextcloud_plugin_kaccounts MODULE target_link_libraries(nextcloud_plugin_kaccounts Qt5::Core Qt5::WebEngineWidgets + Qt5::WebEngine KF5::KIOCore KF5::I18n KF5::Declarative diff --git a/plugins/nextcloud-ui/nextcloudcontroller.cpp b/plugins/nextcloud-ui/nextcloudcontroller.cpp index 9b0bf9105237a8767e61bdc5ea47b0d66204ee05..59b288f82990d34aa1994d284a9cbb0ae07be46f 100644 --- a/plugins/nextcloud-ui/nextcloudcontroller.cpp +++ b/plugins/nextcloud-ui/nextcloudcontroller.cpp @@ -22,9 +22,21 @@ #include #include +// Document for login flow : https://docs.nextcloud.com/server/stable/developer_manual/client_apis/LoginFlow/index.html + +void NextcloudUrlIntercepter::interceptRequest(QWebEngineUrlRequestInfo &info) +{ + info.setHttpHeader("OCS-APIREQUEST", "true"); +} + NextcloudController::NextcloudController(QObject *parent) : QObject(parent) + , m_webengineProfile(new QQuickWebEngineProfile(this)) { + m_webengineProfile->setUrlRequestInterceptor(&m_urlIntercepter); + m_webengineProfile->setHttpUserAgent(QStringLiteral("Mozilla/5.0 nextcloud-ui-plugin")); + + QDesktopServices::setUrlHandler("nc", this, "finalUrlHandler"); } NextcloudController::~NextcloudController() @@ -88,6 +100,9 @@ void NextcloudController::fileChecked(KJob* job) QUrl url = KIO::upUrl(kJob->url()); m_server = url.toString(); + m_loginUrl = m_server + QStringLiteral("/index.php/login/flow"); + Q_EMIT loginUrlChanged(); + m_state = WebLogin; Q_EMIT stateChanged(); // Call webview for login diff --git a/plugins/nextcloud-ui/nextcloudcontroller.h b/plugins/nextcloud-ui/nextcloudcontroller.h index 5c4047b4e425380b79885a3ba39e57c7f5cc7c9a..b51092fb52e5ffbbac076b078fbb4f04462d778f 100644 --- a/plugins/nextcloud-ui/nextcloudcontroller.h +++ b/plugins/nextcloud-ui/nextcloudcontroller.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include namespace KIO { @@ -22,6 +24,11 @@ namespace KIO class KJob; +class NextcloudUrlIntercepter : public QWebEngineUrlRequestInterceptor +{ + void interceptRequest(QWebEngineUrlRequestInfo &info) override; +}; + class NextcloudController : public QObject { Q_OBJECT @@ -29,6 +36,8 @@ class NextcloudController : public QObject Q_PROPERTY(bool isLoginComplete READ isLoginComplete NOTIFY isLoginCompleteChanged) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) Q_PROPERTY(State state MEMBER m_state NOTIFY stateChanged) + Q_PROPERTY(QQuickWebEngineProfile *webengineProfile MEMBER m_webengineProfile CONSTANT) + Q_PROPERTY(QString loginUrl MEMBER m_loginUrl NOTIFY loginUrlChanged) public: @@ -54,6 +63,7 @@ Q_SIGNALS: void isLoginCompleteChanged(); void wizardFinished(const QString &username, const QString &password, const QVariantMap &data); void stateChanged(); + void loginUrlChanged(); private Q_SLOTS: void fileChecked(KJob *job); @@ -80,6 +90,9 @@ private: bool m_isWorking = false; bool m_isLoginComplete = false; State m_state = ServerUrl; + QQuickWebEngineProfile *m_webengineProfile; + NextcloudUrlIntercepter m_urlIntercepter; + QString m_loginUrl; };