File indexing completed on 2024-04-21 04:56:32
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Alejandro Fiestas Olivares <afiestas@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef GET_CREDENTIALS_JOB_H 0008 #define GET_CREDENTIALS_JOB_H 0009 0010 #include "kaccounts_export.h" 0011 0012 #include <Accounts/Account> 0013 #include <KJob> 0014 0015 namespace Accounts 0016 { 0017 class Manager; 0018 } 0019 0020 namespace KAccounts 0021 { 0022 0023 /** 0024 * @brief A KJob for obtaining user's credentials for the given Accounts::AccountId 0025 */ 0026 class KACCOUNTS_EXPORT GetCredentialsJob : public KJob 0027 { 0028 Q_OBJECT 0029 public: 0030 /** 0031 * Constructs the job with auth method and mechanism coming from the service 0032 * type. If no service type is specified, the default will be used 0033 * 0034 * @param id AccountId for which the credentials will be obtained 0035 */ 0036 explicit GetCredentialsJob(Accounts::AccountId id, QObject *parent = nullptr); 0037 /** 0038 * This version of the constructor allow passing specific auth method and mechanism 0039 * for which we want the credentials 0040 * 0041 * For example some account has OAuth token and username-password credentials, 0042 * by setting both method and mechanism to "password", only the password will be 0043 * retrieved. Otherwise it depends on the passed serviceType - if there's no serviceType 0044 * set, it will use the default service for the given AccountId and will obtain 0045 * the credentials needed for that service 0046 * 0047 * @param id AccountId for which the credentials will be obtained 0048 * @param authMethod Auth method for which the credentials will be obtained 0049 * @param authMechanism Auth mechanism for which the credentials will be obtained 0050 */ 0051 GetCredentialsJob(Accounts::AccountId id, const QString &authMethod = QString(), const QString &authMechanism = QString(), QObject *parent = nullptr); 0052 0053 ~GetCredentialsJob() override; 0054 /** 0055 * Starts the credentials job 0056 */ 0057 void start() override; 0058 0059 /** 0060 * Set service for which the auth method and mechanism will be selected 0061 * 0062 * @param serviceType Account's service type 0063 */ 0064 void setServiceType(const QString &serviceType); 0065 0066 /** 0067 * The obtained credentials data 0068 * 0069 * This will be valid only after the job has finished 0070 * 0071 * @returns Map with the credentials 0072 */ 0073 QVariantMap credentialsData() const; 0074 0075 /** 0076 * @returns Account id for which the credentials are obtained 0077 */ 0078 Accounts::AccountId accountId() const; 0079 0080 private: 0081 class Private; 0082 Private *const d; 0083 Q_PRIVATE_SLOT(d, void getCredentials()) 0084 }; 0085 0086 }; 0087 0088 #endif // GET_CREDENTIALS_JOB_H