From 4102144290312ebed7d4af69dd640835275a9675 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 13 Mar 2020 18:39:59 +0100 Subject: Connection: support getting the list of login flows The flows themselves are not facilitated in any way (yet). --- lib/connection.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'lib/connection.h') diff --git a/lib/connection.h b/lib/connection.h index b57f0ca8..9d89ca43 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -21,6 +21,7 @@ #include "joinstate.h" #include "qt_connection_util.h" +#include "csapi/login.h" #include "csapi/create_room.h" #include "events/accountdataevents.h" @@ -36,6 +37,8 @@ namespace QtOlm { class Account; } +Q_DECLARE_METATYPE(Quotient::GetLoginFlowsJob::LoginFlow) + namespace Quotient { Q_NAMESPACE @@ -58,6 +61,28 @@ class SendToDeviceJob; class SendMessageJob; class LeaveRoomJob; +// To simplify comparisons of LoginFlows + +inline bool operator==(const GetLoginFlowsJob::LoginFlow& lhs, + const GetLoginFlowsJob::LoginFlow& rhs) +{ + return lhs.type == rhs.type; +} + +inline bool operator!=(const GetLoginFlowsJob::LoginFlow& lhs, + const GetLoginFlowsJob::LoginFlow& rhs) +{ + return !(lhs == rhs); +} + +/// Predefined login flows +struct LoginFlows { + using LoginFlow = GetLoginFlowsJob::LoginFlow; + static inline const LoginFlow Password { "m.login.password" }; + static inline const LoginFlow SSO { "m.login.sso" }; + static inline const LoginFlow Token { "m.login.token" }; +}; + class Connection; using room_factory_t = @@ -117,6 +142,9 @@ class Connection : public QObject { Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged) Q_PROPERTY(QString domain READ domain NOTIFY homeserverChanged) + Q_PROPERTY(QVector loginFlows READ loginFlows NOTIFY loginFlowsChanged) + Q_PROPERTY(bool supportsSso READ supportsSso NOTIFY loginFlowsChanged) + Q_PROPERTY(bool supportsPasswordAuth READ supportsPasswordAuth NOTIFY loginFlowsChanged) Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged) Q_PROPERTY(bool lazyLoading READ lazyLoading WRITE setLazyLoading NOTIFY @@ -281,6 +309,12 @@ public: QUrl homeserver() const; /** Get the domain name used for ids/aliases on the server */ QString domain() const; + /** Get the list of supported login flows */ + QVector loginFlows() const; + /** Check whether the current homeserver supports password auth */ + bool supportsPasswordAuth() const; + /** Check whether the current homeserver supports SSO */ + bool supportsSso() const; /** Find a room by its id and a mask of applicable states */ Q_INVOKABLE Quotient::Room* room(const QString& roomId, @@ -421,6 +455,18 @@ public: std::forward(jobArgs)...); } + /*! Get a request URL for a job with specified type and arguments + * + * This calls JobT::makeRequestUrl() prepending the connection's homeserver + * to the list of arguments. + */ + template + QUrl getUrlForApi(JobArgTs&&... jobArgs) const + { + return JobT::makeRequestUrl(homeserver(), + std::forward(jobArgs)...); + } + /** Generate a new transaction id. Transaction id's are unique within * a single Connection object */ @@ -609,6 +655,7 @@ signals: void resolveError(QString error); void homeserverChanged(QUrl baseUrl); + void loginFlowsChanged(); void capabilitiesLoaded(); void connected(); -- cgit v1.2.3 From d02a510a586db1a89476cd283ea24a281e9bb6af Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 15 Mar 2020 14:53:27 +0100 Subject: Connection: loginWithToken(); connectWithToken() -> assumeIdentity() --- lib/connection.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib/connection.h') diff --git a/lib/connection.h b/lib/connection.h index 9d89ca43..8f2abd0f 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -505,11 +505,23 @@ public slots: /** Determine and set the homeserver from MXID */ void resolveServer(const QString& mxid); - void connectToServer(const QString& user, const QString& password, + void connectToServer(const QString& userId, const QString& password, const QString& initialDeviceName, const QString& deviceId = {}); + void loginWithToken(const QByteArray& loginToken, + const QString& initialDeviceName, + const QString& deviceId = {}); + void assumeIdentity(const QString& userId, const QString& accessToken, + const QString& deviceId); + /*! @deprecated + * Use assumeIdentity() if you have an access token or + * loginWithToken() if you have a login token. + */ void connectWithToken(const QString& userId, const QString& accessToken, - const QString& deviceId); + const QString& deviceId) + { + assumeIdentity(userId, accessToken, deviceId); + } /// Explicitly request capabilities from the server void reloadCapabilities(); @@ -856,9 +868,6 @@ private: * @param connectFn - a function to execute once the HS URL is good */ void checkAndConnect(const QString& userId, std::function connectFn); - void doConnectToServer(const QString& user, const QString& password, - const QString& initialDeviceName, - const QString& deviceId = {}); static room_factory_t _roomFactory; static user_factory_t _userFactory; -- cgit v1.2.3 From ab3d0263b770e30de673c63740a5c26bcbf33e58 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 18 Mar 2020 09:51:27 +0100 Subject: SsoSession and Connection::prepareForSso() The response in the web browser is quite barebone, just enough to give feedback that things are alright. Closes #386. Closes #388. --- lib/connection.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/connection.h') diff --git a/lib/connection.h b/lib/connection.h index 8f2abd0f..9b222ca8 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -18,6 +18,7 @@ #pragma once +#include "ssosession.h" #include "joinstate.h" #include "qt_connection_util.h" @@ -467,6 +468,9 @@ public: std::forward(jobArgs)...); } + Q_INVOKABLE SsoSession* prepareForSso(const QString& initialDeviceName, + const QString& deviceId = {}); + /** Generate a new transaction id. Transaction id's are unique within * a single Connection object */ -- cgit v1.2.3