| 1 | /* |
| 2 | * This file is part of libOnlineAccounts |
| 3 | * |
| 4 | * Copyright (C) 2015-2016 Canonical Ltd. |
| 5 | * |
| 6 | * Contact: Alberto Mardegan <[email protected]> |
| 7 | * |
| 8 | * This program is free software: you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU Lesser General Public License version 3, as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
| 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 15 | * PURPOSE. See the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #ifndef ONLINE_ACCOUNTS_AUTHENTICATION_DATA_H |
| 22 | #define ONLINE_ACCOUNTS_AUTHENTICATION_DATA_H |
| 23 | |
| 24 | #include <QByteArray> |
| 25 | #include <QList> |
| 26 | #include <QSharedDataPointer> |
| 27 | |
| 28 | #include "error.h" |
| 29 | #include "global.h" |
| 30 | #include "pending_call.h" |
| 31 | |
| 32 | namespace OnlineAccounts { |
| 33 | |
| 34 | class Manager; |
| 35 | |
| 36 | class AuthenticationDataPrivate; |
| 37 | class ONLINE_ACCOUNTS_EXPORT AuthenticationData |
| 38 | { |
| 39 | public: |
| 40 | AuthenticationData(AuthenticationMethod method); |
| 41 | AuthenticationData(const AuthenticationData &other); |
| 42 | virtual ~AuthenticationData(); |
| 43 | |
| 44 | AuthenticationMethod method() const; |
| 45 | |
| 46 | void setInteractive(bool interactive); |
| 47 | bool interactive() const; |
| 48 | |
| 49 | void invalidateCachedReply(); |
| 50 | bool mustInvalidateCachedReply() const; |
| 51 | |
| 52 | void setParameters(const QVariantMap ¶meters); |
| 53 | QVariantMap parameters() const; |
| 54 | |
| 55 | protected: |
| 56 | AuthenticationData(AuthenticationDataPrivate *priv); |
| 57 | QSharedDataPointer<AuthenticationDataPrivate> d; |
| 58 | |
| 59 | private: |
| 60 | friend class Manager; |
| 61 | friend class ManagerPrivate; |
| 62 | }; |
| 63 | |
| 64 | class AuthenticationReplyPrivate; |
| 65 | class ONLINE_ACCOUNTS_EXPORT AuthenticationReply |
| 66 | { |
| 67 | public: |
| 68 | AuthenticationReply(const PendingCall &call); |
| 69 | virtual ~AuthenticationReply(); |
| 70 | |
| 71 | bool hasError() const { return error().isValid(); } |
| 72 | Error error() const; |
| 73 | |
| 74 | QVariantMap data() const; |
| 75 | |
| 76 | protected: |
| 77 | AuthenticationReply(AuthenticationReplyPrivate *priv); |
| 78 | AuthenticationReplyPrivate *d_ptr; |
| 79 | |
| 80 | private: |
| 81 | Q_DECLARE_PRIVATE(AuthenticationReply) |
| 82 | Q_DISABLE_COPY(AuthenticationReply) |
| 83 | }; |
| 84 | |
| 85 | /* OAuth 2.0 */ |
| 86 | |
| 87 | class ONLINE_ACCOUNTS_EXPORT OAuth2Data: public AuthenticationData |
| 88 | { |
| 89 | public: |
| 90 | OAuth2Data(); |
| 91 | |
| 92 | void setClientId(const QByteArray &id); |
| 93 | QByteArray clientId() const; |
| 94 | |
| 95 | void setClientSecret(const QByteArray &secret); |
| 96 | QByteArray clientSecret() const; |
| 97 | |
| 98 | void setScopes(const QList<QByteArray> &scopes); |
| 99 | QList<QByteArray> scopes() const; |
| 100 | }; |
| 101 | |
| 102 | class OAuth2ReplyPrivate; |
| 103 | class ONLINE_ACCOUNTS_EXPORT OAuth2Reply: public AuthenticationReply |
| 104 | { |
| 105 | public: |
| 106 | OAuth2Reply(const PendingCall &call); |
| 107 | ~OAuth2Reply(); |
| 108 | |
| 109 | QByteArray accessToken() const; |
| 110 | int expiresIn() const; |
| 111 | QList<QByteArray> grantedScopes() const; |
| 112 | |
| 113 | private: |
| 114 | Q_DECLARE_PRIVATE(OAuth2Reply) |
| 115 | Q_DISABLE_COPY(OAuth2Reply) |
| 116 | }; |
| 117 | |
| 118 | /* OAuth 1.0a */ |
| 119 | |
| 120 | class ONLINE_ACCOUNTS_EXPORT OAuth1Data: public AuthenticationData |
| 121 | { |
| 122 | public: |
| 123 | OAuth1Data(); |
| 124 | |
| 125 | void setConsumerKey(const QByteArray &consumerKey); |
| 126 | QByteArray consumerKey() const; |
| 127 | |
| 128 | void setConsumerSecret(const QByteArray &consumerSecret); |
| 129 | QByteArray consumerSecret() const; |
| 130 | }; |
| 131 | |
| 132 | class OAuth1ReplyPrivate; |
| 133 | class ONLINE_ACCOUNTS_EXPORT OAuth1Reply: public AuthenticationReply |
| 134 | { |
| 135 | public: |
| 136 | OAuth1Reply(const PendingCall &call); |
| 137 | ~OAuth1Reply(); |
| 138 | |
| 139 | QByteArray consumerKey() const; |
| 140 | QByteArray consumerSecret() const; |
| 141 | QByteArray token() const; |
| 142 | QByteArray tokenSecret() const; |
| 143 | QByteArray signatureMethod() const; |
| 144 | |
| 145 | private: |
| 146 | Q_DECLARE_PRIVATE(OAuth1Reply) |
| 147 | Q_DISABLE_COPY(OAuth1Reply) |
| 148 | }; |
| 149 | |
| 150 | /* SASL */ |
| 151 | |
| 152 | class ONLINE_ACCOUNTS_EXPORT SaslData: public AuthenticationData |
| 153 | { |
| 154 | public: |
| 155 | SaslData(); |
| 156 | |
| 157 | void setService(const QString &service); |
| 158 | QString service() const; |
| 159 | |
| 160 | void setMechanismList(const QByteArray &mechanisms); |
| 161 | QByteArray mechanismList() const; |
| 162 | |
| 163 | void setServerFqdn(const QString &fqdn); |
| 164 | QString serverFqdn() const; |
| 165 | |
| 166 | void setLocalIp(const QString &localIp); |
| 167 | QString localIp() const; |
| 168 | |
| 169 | void setRemoteIp(const QString &remoteIp); |
| 170 | QString remoteIp() const; |
| 171 | |
| 172 | void setChallenge(const QByteArray &challenge); |
| 173 | QByteArray challenge() const; |
| 174 | }; |
| 175 | |
| 176 | class SaslReplyPrivate; |
| 177 | class ONLINE_ACCOUNTS_EXPORT SaslReply: public AuthenticationReply |
| 178 | { |
| 179 | public: |
| 180 | enum State { |
| 181 | Finished, |
| 182 | Continue, |
| 183 | }; |
| 184 | |
| 185 | SaslReply(const PendingCall &call); |
| 186 | ~SaslReply(); |
| 187 | |
| 188 | QString chosenMechanism() const; |
| 189 | QByteArray response() const; |
| 190 | State state() const; |
| 191 | |
| 192 | private: |
| 193 | Q_DECLARE_PRIVATE(SaslReply) |
| 194 | Q_DISABLE_COPY(SaslReply) |
| 195 | }; |
| 196 | |
| 197 | /* Password */ |
| 198 | |
| 199 | class ONLINE_ACCOUNTS_EXPORT PasswordData: public AuthenticationData |
| 200 | { |
| 201 | public: |
| 202 | PasswordData(); |
| 203 | }; |
| 204 | |
| 205 | class PasswordReplyPrivate; |
| 206 | class ONLINE_ACCOUNTS_EXPORT PasswordReply: public AuthenticationReply |
| 207 | { |
| 208 | public: |
| 209 | PasswordReply(const PendingCall &call); |
| 210 | ~PasswordReply(); |
| 211 | |
| 212 | QByteArray username() const; |
| 213 | QByteArray password() const; |
| 214 | |
| 215 | private: |
| 216 | Q_DECLARE_PRIVATE(PasswordReply) |
| 217 | Q_DISABLE_COPY(PasswordReply) |
| 218 | }; |
| 219 | |
| 220 | } // namespace |
| 221 | |
| 222 | #endif // ONLINE_ACCOUNTS_AUTHENTICATION_DATA_H |