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: HttpCredentialsGui()32 explicit HttpCredentialsGui() 33 : HttpCredentials() 34 { 35 } HttpCredentialsGui(const QString & user,const QString & password,const QByteArray & clientCertBundle,const QByteArray & clientCertPassword)36 HttpCredentialsGui(const QString &user, const QString &password, 37 const QByteArray &clientCertBundle, const QByteArray &clientCertPassword) 38 : HttpCredentials(user, password, clientCertBundle, clientCertPassword) 39 { 40 } HttpCredentialsGui(const QString & user,const QString & password,const QString & refreshToken,const QByteArray & clientCertBundle,const QByteArray & clientCertPassword)41 HttpCredentialsGui(const QString &user, const QString &password, const QString &refreshToken, 42 const QByteArray &clientCertBundle, const QByteArray &clientCertPassword) 43 : HttpCredentials(user, password, clientCertBundle, clientCertPassword) 44 { 45 _refreshToken = refreshToken; 46 } 47 48 /** 49 * This will query the server and either uses OAuth via _asyncAuth->start() 50 * or call showDialog to ask the password 51 */ 52 void askFromUser() override; 53 /** 54 * In case of oauth, return an URL to the link to open the browser. 55 * An invalid URL otherwise 56 */ authorisationLink()57 QUrl authorisationLink() const { return _asyncAuth ? _asyncAuth->authorisationLink() : QUrl(); } 58 59 60 static QString requestAppPasswordText(const Account *account); 61 private slots: 62 void asyncAuthResult(OAuth::Result, const QString &user, const QString &accessToken, const QString &refreshToken); 63 void showDialog(); 64 void askFromUserAsync(); 65 66 signals: 67 void authorisationLinkChanged(); 68 69 private: 70 71 QScopedPointer<OAuth, QScopedPointerObjectDeleteLater<OAuth>> _asyncAuth; 72 }; 73 74 } // namespace OCC 75