Representation of an online account. More...
Import Statement: | import Lomiri.OnlineAccounts 2.0 |
The Account object holds the information related to an account and provides methods to interact with it. It's not possible to create such objects from QML; instead, they are returned by the AccountModel in the account
role or in the accountList
property.
Here's an example on how to use the account object in a delegate:
import QtQuick 2.0 import Lomiri.OnlineAccounts 2.0 ListView { model: AccountModel {} delegate: Button { text: "Authenticate " + model.displayName onClicked: model.account.authenticate({}) Connections { target: model.account onAuthenticationReply: { console.log("Access token is " + reply['AccessToken']) } } } }
Some operations, such as the Account::authenticate() and the AccountModel::requestAccess() methods, can fail and return one of these error codes:
Account.ErrorCodeNoAccount
- The accounts is invalidAccount.ErrorCodeUserCanceled
- The operation was canceled by the userAccount.ErrorCodePermissionDenied
- The application has no permission to complete the operationNumeric identifier of the account. This property remains constant during the lifetime of the account. Note, however, that if the user deletes the account and re-creates it, its ID will be different.
The authentication method used when authenticating with the account. Currently, these authentication methods are supported:
Account.AuthenticationMethodOAuth1
- OAuth 1.0Account.AuthenticationMethodOAuth2
- OAuth 2.0Account.AuthenticationMethodSasl
- SASLAccount.AuthenticationMethodPassword
- username/passwordThe display name of the account. This is usually the user's login name, but applications should not rely on the value of this property. Use it only for display purposes.
Service data associated with this account. This is an object containing the following properties:
serviceId
- same service ID returned by Account::serviceIddisplayName
- the localized display name for the serviceiconSource
- URL for the icon; can be a "file://" URL to a local file, or an icon from the theme if the URL starts with "image://theme/"Whether the account object is valid; this is usually true
, because the AccountModel
never gives out invalid accounts. However, it can happen that a valid account becomes invalid while the application is using it (if, for instance, the user deleted the account or revoked the application's access rights to use it). As soon as this property becomes false
, the application should stop using this account.
Emitted when the authentication completes. The authenticationData object will contain the authentication reply. If the authentication failed, the following two keys will be present:
errorCode
is an error codeerrorText
is a textual description of the error, not meant for the end-user; it can be used for debugging purposesPerform the authentication on this account. The params parameter can be used to pass authentication data, such as the ClientId and ClientSecret used in the OAuth flow. The list of the supported authentication parameters depend on the authentication method being used, and are documented in the Online Accounts development Guide in the UBports Developer Portal.
There are, however, two authentication parameters which are available regardless of the authentication method being used:
invalidateCachedReply
can be set to true
when the previous authentication reply returned an invalid access token. It will ensure the creation of a new access token.interactive
is true
by default; if set to false
, it will ensure that no interaction with the user will occur.Each call to this method will cause the authenticationReply signal to be emitted at some time later. Note that the authentication might involve interactions with the network or with the end-user, so don't expect a reply to be emitted immediately.
See also authenticationReply.