File indexing completed on 2024-11-17 04:18:47

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef NEXTCLOUDAUTHENTICATOR_H
0007 #define NEXTCLOUDAUTHENTICATOR_H
0008 
0009 #include <QObject>
0010 #include <QString>
0011 #include <QUrl>
0012 
0013 class QNetworkAccessManager;
0014 class QNetworkReply;
0015 
0016 /** Implementation of https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/index.html#login-flow-v2. */
0017 class NextcloudAuthenticator : public QObject
0018 {
0019     Q_OBJECT
0020 public:
0021     explicit NextcloudAuthenticator(QObject *parent = nullptr);
0022     ~NextcloudAuthenticator();
0023 
0024     void setNetworkAccessManager(QNetworkAccessManager *nam);
0025     void authenticate(const QUrl &baseUrl, const QString &appName);
0026 
0027 Q_SIGNALS:
0028     void authenticated(const QString &loginName, const QString &appPassword);
0029 
0030 private:
0031     void post1Finished(QNetworkReply *reply);
0032     void login2Poll();
0033 
0034     QNetworkAccessManager *m_nam = nullptr;
0035     QUrl m_pollEndpoint;
0036     QByteArray m_pollToken;
0037 };
0038 
0039 #endif // NEXTCLOUDAUTHENTICATOR_H