Line data Source code
1 : #pragma once
2 :
3 : #include <QObject>
4 : #include <QUrl>
5 :
6 : class QNetworkAccessManager;
7 : class QNetworkReply;
8 : class QTimer;
9 :
10 : // T-158: Nextcloud Login Flow v2 authentication.
11 : // Opens the system browser for the user to log in, then polls
12 : // the Nextcloud server until an app password is granted.
13 : class NextcloudAuth : public QObject {
14 8 : Q_OBJECT
15 :
16 : public:
17 : explicit NextcloudAuth(QObject *parent = nullptr);
18 : ~NextcloudAuth() override;
19 :
20 : // Start the login flow for the given Nextcloud server URL.
21 : void startLogin(const QString &serverUrl);
22 : static bool isServerUrlAllowedForLogin(const QUrl &url);
23 :
24 : // Cancel an ongoing login flow.
25 : void cancel();
26 :
27 : // Test seam (same pattern as CalDavClient): replace the network access
28 : // manager; ownership transfers to this object.
29 : void setNetworkAccessManager(QNetworkAccessManager *nam);
30 :
31 : bool isPolling() const;
32 :
33 : signals:
34 : void loginSuccess(const QString &server, const QString &loginName,
35 : const QString &appPassword);
36 : void loginFailed(const QString &error);
37 :
38 : private slots:
39 : void onInitReply();
40 : void poll();
41 :
42 : private:
43 : QNetworkAccessManager *m_nam = nullptr;
44 : QTimer *m_pollTimer = nullptr;
45 : QNetworkReply *m_currentReply = nullptr;
46 :
47 : QString m_pollEndpoint;
48 : QString m_pollToken;
49 : QString m_originalServerUrl; // T-611/SEC-10: For SSRF origin validation
50 : int m_pollCount = 0;
51 : static constexpr int MaxPollAttempts = 60; // 120 seconds at 2s interval
52 : };
|