1 | /* |
2 | * Copyright (C) by Klaas Freitag <freitag@kde.org> |
3 | * Copyright (C) by Olivier Goffart <ogoffart@woboq.com> |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13 | * for more details. |
14 | */ |
15 | |
16 | #pragma once |
17 | #include "creds/httpcredentials.h" |
18 | #include "creds/oauth.h" |
19 | #include <QPointer> |
20 | #include <QTcpServer> |
21 | |
22 | namespace OCC { |
23 | |
24 | /** |
25 | * @brief The HttpCredentialsGui class |
26 | * @ingroup gui |
27 | */ |
28 | class HttpCredentialsGui : public HttpCredentials |
29 | { |
30 | Q_OBJECT |
31 | public: |
32 | explicit HttpCredentialsGui() |
33 | : HttpCredentials() |
34 | { |
35 | } |
36 | HttpCredentialsGui(const QString &user, const QString &password, const QSslCertificate &certificate, const QSslKey &key) |
37 | : HttpCredentials(user, password, certificate, key) |
38 | { |
39 | } |
40 | HttpCredentialsGui(const QString &user, const QString &password, const QString &refreshToken, |
41 | const QSslCertificate &certificate, const QSslKey &key) |
42 | : HttpCredentials(user, password, certificate, key) |
43 | { |
44 | _refreshToken = refreshToken; |
45 | } |
46 | |
47 | /** |
48 | * This will query the server and either uses OAuth via _asyncAuth->start() |
49 | * or call showDialog to ask the password |
50 | */ |
51 | void askFromUser() Q_DECL_OVERRIDE; |
52 | /** |
53 | * In case of oauth, return an URL to the link to open the browser. |
54 | * An invalid URL otherwise |
55 | */ |
56 | QUrl authorisationLink() const { return _asyncAuth ? _asyncAuth->authorisationLink() : QUrl(); } |
57 | |
58 | |
59 | static QString requestAppPasswordText(const Account *account); |
60 | private slots: |
61 | void asyncAuthResult(OAuth::Result, const QString &user, const QString &accessToken, const QString &refreshToken); |
62 | void showDialog(); |
63 | void askFromUserAsync(); |
64 | |
65 | signals: |
66 | void authorisationLinkChanged(); |
67 | |
68 | private: |
69 | |
70 | QScopedPointer<OAuth, QScopedPointerObjectDeleteLater<OAuth>> _asyncAuth; |
71 | }; |
72 | |
73 | } // namespace OCC |
74 | |