1 /* 2 * This file is part of LibKGAPI 3 * 4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 5 * 6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 7 */ 8 9 #pragma once 10 11 #include "job.h" 12 #include "kgapicore_export.h" 13 14 class QWidget; 15 16 namespace KGAPI2 { 17 18 /** 19 * @headerfile authjob.h 20 * @brief A job to authenticate against Google and fetch tokens 21 * 22 * This job can be either used to refresh expired tokens (this is usually done 23 * automatically by Job implementation), or to request tokens for a new account. 24 * 25 * In the latter case, the AuthJob will automatically open a browser window 26 * where user has to provide Google account credentials and grant access to all 27 * requested scopes (@see Account::scopes). 28 * 29 * @author Daniel Vrátil <dvratil@redhat.com> 30 * @since 2.0 31 */ 32 class KGAPICORE_EXPORT AuthJob : public KGAPI2::Job 33 { 34 Q_OBJECT 35 36 public: 37 /** 38 * @brief Creates a new authentication job 39 * 40 * When constructed without a parent, or with a non-QWidget parent, the 41 * job might pop up the authentication dialog. 42 * 43 * @param account Account to authenticate. 44 * @param apiKey Application API key 45 * @param secretKey Application secret API key 46 * @param parent 47 */ 48 explicit AuthJob(const AccountPtr &account, const QString &apiKey, 49 const QString &secretKey, QObject* parent = nullptr); 50 51 /** 52 * @brief Destructor 53 */ 54 ~AuthJob() override; 55 56 /** 57 * @brief Returns reauthenticated account. 58 * 59 * @returns An account pointer passed to the AuthJob() constructor with 60 * all fields filled and validated. When the job fails, the account 61 * is unchanged. 62 */ 63 AccountPtr account() const; 64 65 /** 66 * Sets the username that will be used when authenticate is called 67 * 68 * @param username username to use 69 */ 70 void setUsername(const QString &username); 71 72 /** 73 * Sets the password that will be used when authenticate is called 74 * 75 * @param password password to use 76 * @deprecated 77 */ 78 QT_DEPRECATED_X("It's no longer possible to prefill password") 79 void setPassword(const QString &password); 80 81 protected: 82 /** 83 * @brief KGAPI2::Job::handleReply implementation 84 * 85 * @param reply 86 * @param rawData 87 */ 88 void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override; 89 90 /** 91 * @brief KGAPI2::Job::displayRequest implementation 92 * 93 * @param accessManager 94 * @param request 95 * @param data 96 * @param contentType 97 */ 98 void dispatchRequest(QNetworkAccessManager* accessManager, 99 const QNetworkRequest& request, 100 const QByteArray& data, 101 const QString& contentType) override; 102 103 /** 104 * @brief KGAPI2::Job::start implementation 105 */ 106 void start() override; 107 108 private: 109 class Private; 110 QScopedPointer<Private> const d; 111 friend class Private; 112 }; 113 114 } // namespace KGAPI2 115 116