70
70
map["errorCode"] = reply.error().code();
71
71
map["errorText"] = reply.error().text();
73
map = replyToMap(*watcher, m_account->authenticationMethod());
73
map = replyToMap(*watcher);
76
76
Q_EMIT q->authenticationReply(map);
81
* \inqmlmodule Ubuntu.OnlineAccounts 2.0
83
* \brief Representation of an online account
85
* The Account object holds the information related to an account and provides
86
* methods to interact with it.
87
* It's not possible to create such objects from QML; instead, they are
88
* returned by the \l AccountModel in the \c account role or in the \l
89
* {AccountModel::accountList} { \c accountList} property.
91
* Here's an example on how to use the account object in a delegate:
95
* import Ubuntu.OnlineAccounts 2.0
98
* model: AccountModel {}
100
* text: "Authenticate " + model.displayName
101
* onClicked: model.account.authenticate({})
103
* target: model.account
104
* onAuthenticationReply: {
105
* console.log("Access token is " + reply['AccessToken'])
113
* \section3 Error codes used in this module
114
* Some operations, such as the \l Account::authenticate() and the \l
115
* AccountModel::requestAccess() methods, can fail and return one of these
118
* \li \c Account.ErrorCodeNoAccount - The accounts is invalid
119
* \li \c Account.ErrorCodeUserCanceled - The operation was canceled by the user
120
* \li \c Account.ErrorCodePermissionDenied - The application has no
121
* permission to complete the operation
79
125
Account::Account(OnlineAccounts::Account *account, QObject *parent):
81
127
d_ptr(new AccountPrivate(account, this))
137
* \qmlproperty bool Account::valid
139
* Whether the account object is valid; this is usually \c true, because the \c
140
* AccountModel never gives out invalid accounts. However, it can happen that a
141
* valid account becomes invalid while the application is using it (if, for
142
* instance, the user deleted the account or revoked the application's access
143
* rights to use it). As soon as this property becomes \c false, the
144
* application should stop using this account.
90
146
bool Account::isValid() const
92
148
Q_D(const Account);
93
149
return d->m_account->isValid();
153
* \qmlproperty string Account::displayName
155
* The display name of the account. This is usually the user's login name, but
156
* applications should not rely on the value of this property. Use it only for
96
159
QString Account::displayName() const
98
161
Q_D(const Account);
99
162
return d->m_account->displayName();
166
* \qmlproperty int Account::accountId
168
* Numeric identifier of the account. This property remains constant during the
169
* lifetime of the account. Note, however, that if the user deletes the account
170
* and re-creates it, its ID will be different.
102
172
int Account::accountId() const
104
174
Q_D(const Account);
105
175
return d->m_account->id();
179
* \qmlproperty int Account::serviceId
181
* Identifier for the service used with the account.
108
183
QString Account::serviceId() const
110
185
Q_D(const Account);
111
186
return d->m_account->serviceId();
190
* \qmlproperty enumeration Account::authenticationMethod
192
* The authentication method used when authenticating with the account.
193
* Currently, these authentication methods are supported:
195
* \li \c Account.AuthenticationMethodOAuth1 - OAuth 1.0
196
* \li \c Account.AuthenticationMethodOAuth2 - OAuth 2.0
197
* \li \c Account.AuthenticationMethodPassword - username/password
114
200
Account::AuthenticationMethod Account::authenticationMethod() const
116
202
Q_D(const Account);
117
203
return AuthenticationMethod(d->m_account->authenticationMethod());
207
* \qmlproperty jsobject Account::settings
209
* A dictionary of the settings stored into the account.
120
211
QVariantMap Account::settings() const
122
/* FIXME: libOnlineAccountsQt lacks a way to retrieve the list of settings;
123
* until that is available, we cannot do much here */
124
return QVariantMap();
215
Q_FOREACH(const QString &key, d->m_account->keys()) {
216
ret.insert(key, d->m_account->setting(key));
127
221
OnlineAccounts::Account *Account::internalObject() const
130
224
return d->m_account;
228
* \qmlsignal Account::authenticationReply(jsobject authenticationData)
230
* Emitted when the authentication completes. The \a authenticationData object
231
* will contain the authentication reply. If the authentication failed, the
232
* following two keys will be present:
234
* \li \c errorCode is an \l {errorCode} {error code}
235
* \li \c errorText is a textual description of the error, not meant for the
236
* end-user; it can be used for debugging purposes
241
* \qmlmethod void Account::authenticate(jsobject params)
243
* Perform the authentication on this account. The \a params parameter can be
244
* used to pass authentication data, such as the ClientId and ClientSecret used
245
* in the OAuth flow. The list of the supported authentication parameters
246
* depend on the authentication method being used, and are documented in the
247
* Online Accounts development Guide in the Ubuntu Developer Portal.
249
* There are, however, two authentication parameters which are available
250
* regardless of the authentication method being used:
252
* \li \c invalidateCachedReply can be set to \c true when the previous
253
* authentication reply returned an invalid access token. It will ensure
254
* the creation of a new access token.
255
* \li \c interactive is \c true by default; if set to \c false, it will ensure
256
* that no interaction with the user will occur.
259
* Each call to this method will cause the \l authenticationReply signal to be
260
* emitted at some time later. Note that the authentication might involve
261
* interactions with the network or with the end-user, so don't expect a reply
262
* to be emitted immediately.
264
* \sa authenticationReply
133
266
void Account::authenticate(const QVariantMap ¶ms)