Account API
The basic concepts are:
- Provider is an online service provider entity, such as Google, Vodafone or Facebook. A service provider is identified by its applicationId. Account provider will be registered while the application is installed. The information will be used in the "Add account" screen in Settings.
- Account collects all the data (user name, credential, settings) needed for connecting to services. An account is always bound to a single provider, and has a list of service instances bound to the account. The services can be individually enabled and disabled on the given account. For instance, account1@gmail.com can identify a Google account, giving access to services such as gmail, gtalk, Picasa, and Youtube with each service having a separate service instance bound to the account.
To use add(), remove(), and update() methods of AccountManager a web application needs to be an account provider application.
A web application is an account provider when its config.xml contains Account provider section. For example:
<tizen:account multiple-account-support="true">
<tizen:icon section="Account">icon.png</tizen:icon>
<tizen:icon section="AccountSmall">icon.png</tizen:icon>
<tizen:display-name xml:lang="en-gb">Test</tizen:display-name>
<tizen:capability>http://tizen.org/account/capability/contact</tizen:capability>
</tizen:account>
For more information about how to use Account API, see Account Guide.
Since: 5.0
Table of Contents
- 1. Type Definitions
- 1.1. AccountId
- 2. Interfaces
- 2.1. AccountManagerObject
- 2.2. AccountProvider
- 2.3. AccountInit
- 2.4. Account
- 2.5. AccountManager
- 2.6. AccountExtendedData
- 2.7. AccountArraySuccessCallback
- 2.8. AccountExtendedDataArraySuccessCallback
- 2.9. AccountProviderArraySuccessCallback
- 2.10. AccountChangeCallback
- 3. Related Feature
- 4. Full WebIDL
Summary of Interfaces and Methods
Interface | Method |
---|---|
AccountManagerObject | |
AccountProvider | |
AccountInit | |
Account |
void setExtendedData (DOMString key, DOMString value)
DOMString getExtendedData (DOMString key)
void getExtendedData (AccountExtendedDataArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
|
AccountManager |
void getAccounts (AccountArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? applicationId)
void getProviders (AccountProviderArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? capability)
long addAccountListener (AccountChangeCallback callback)
void removeAccountListener (long accountListenerId)
|
AccountExtendedData | |
AccountArraySuccessCallback | |
AccountExtendedDataArraySuccessCallback | void onsuccess (AccountExtendedData[] extendedDataArray) |
AccountProviderArraySuccessCallback | void onsuccess (AccountProvider[] providers) |
AccountChangeCallback |
2. Interfaces
2.1. AccountManagerObject
[NoInterfaceObject] interface AccountManagerObject { readonly attribute AccountManager account; };
Tizen implements AccountManagerObject;
Since: 5.0
The tizen.account object allows accessing the functionality of the Account API. There is one account manager in one web runtime. The Accounts back-end may support multiple account managers.
Attributes
-
readonly
AccountManager accountObject representing an account manager.
Since: 5.0
2.2. AccountProvider
[NoInterfaceObject] interface AccountProvider { readonly attribute ApplicationId applicationId; readonly attribute DOMString displayName; readonly attribute DOMString iconUri; readonly attribute DOMString smallIconUri; readonly attribute DOMString[] capabilities; readonly attribute boolean isMultipleAccountSupported; };
Since: 5.0
Attributes
-
readonly
ApplicationId applicationIdIdentifier of the account provider application.
Since: 5.0
-
readonly
DOMString displayNameLogical (translatable) display name.
Since: 5.0
-
readonly
DOMString iconUriPath to the icon representing the account provider.
Since: 5.0
-
readonly
DOMString smallIconUriPath to the small icon representing the account provider.
Since: 5.0
-
readonly
DOMString[]
capabilitiesCapabilities of the account provider defined in IRI format.
The following predefined capabilities can be used.
- http://tizen.org/account/capability/contact - Used when the account is related to contacts
- http://tizen.org/account/capability/calendar - Used when the account is related to calendar
Since: 5.0
-
readonly
boolean isMultipleAccountSupportedBoolean value that indicates whether multiple accounts are supported.
Since: 5.0
2.3. AccountInit
dictionary AccountInit { DOMString userName; DOMString iconUri; };
Since: 5.0
2.4. Account
[Constructor(AccountProvider provider, optional AccountInit? accountInitDict)] interface Account { readonly attribute AccountId? id; attribute DOMString? userName; attribute DOMString? iconUri; readonly attribute AccountProvider provider; void setExtendedData(DOMString key, DOMString value) raises(WebAPIException); DOMString getExtendedData(DOMString key) raises(WebAPIException); void getExtendedData(AccountExtendedDataArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 5.0
The information is hidden from web applications.
Constructors
-
Constructor (AccountProvider, AccountInit?)
Account(AccountProvider provider, optional AccountInit? accountInitDict);
Attributes
-
readonly
AccountId id [nullable]Identifier for the account. By default, this attribute is set to null.
Since: 5.0
-
DOMString userName [nullable]Account user name. By default, this attribute is set to null.
Since: 5.0
-
DOMString iconUri [nullable]Name, identifier or URI of the icon. By default, this attribute is set to null.
Since: 5.0
-
readonly
AccountProvider providerReference to the provider. There is one provider for each account. A given provider can be referenced from many accounts.
Since: 5.0
Methods
-
setExtendedData
-
Adds the specified key and value to the extended data.
void setExtendedData(DOMString key, DOMString value);
Since: 5.0
If the specified key already exists, the corresponding value is overwritten with the specified value.
Privilege level: public
Privilege: http://tizen.org/privilege/account.write
Parameters:
- key: Key of the extended data.
- value: Value of the extended data.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type NotFoundError, if account ID is null.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; tizen.account.getAccounts( function(accounts) { var account = accounts[0]; if (account) { var key = "nickname"; var value = "nickname of anonymous user"; account.setExtendedData(key, value); console.log(account.getExtendedData(key)); account.setExtendedData(key, "nickname updated"); console.log(account.getExtendedData(key)); } }, function(e) { console.log("Error: " + e.message); }, appId);
Output example:
"nickname of anonymous user" "nickname updated"
-
getExtendedData
-
Gets the value for the given key from the extended data. Returns null if the given key is not found.
DOMString getExtendedData(DOMString key);
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- key: Key of the extended data.
Return value:
-
DOMString:
Value of the extended data.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type NotFoundError, if account ID is null.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; tizen.account.getAccounts( function(accounts) { var account = accounts[0]; if (account) { var key = "accessToken"; var value = account.getExtendedData(key); console.log(account.userName + "'s accessToken is " + value); } }, function(e) { console.log("Error: " + e.message); }, appId);
-
getExtendedData
-
Gets the extended data for the account as an array, asynchronously. Returns an empty array if there is no extended data.
void getExtendedData(AccountExtendedDataArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- successCallback: Callback method that is invoked when an asynchronous call completes successfully.
- errorCallback [optional] [nullable]: Callback method that is invoked when an error occurs.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type NotFoundError, if account ID is null.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; tizen.account.getAccounts( function(accounts) { var account = accounts[0]; if (account) { account.getExtendedData( function(extendedData) { for (var i = 0; i < extendedData.length; i++) { var key = extendedData.key; var value = extendedData.value; console.log(key + ": " + value); } }, function(e) { console.log("Error: " + e.message); }); } }, function(e) { console.log("Error: " + e.message); }, appId);
2.5. AccountManager
[NoInterfaceObject] interface AccountManager { void add(Account account) raises(WebAPIException); void remove(AccountId accountId) raises(WebAPIException); void update(Account account) raises(WebAPIException); Account? getAccount(AccountId accountId) raises(WebAPIException); void getAccounts(AccountArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? applicationId) raises(WebAPIException); AccountProvider? getProvider(ApplicationId applicationId) raises(WebAPIException); void getProviders(AccountProviderArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? capability) raises(WebAPIException); long addAccountListener(AccountChangeCallback callback) raises(WebAPIException); void removeAccountListener(long accountListenerId) raises(WebAPIException); };
Since: 5.0
Methods
-
add
-
Adds an account to the account database.
void add(Account account);
Since: 5.0
If the account is added successfully, an accountId and provider are newly assigned when the function returns.
This method can be used only by an account provider application.
If the application is registered as provider, it will be launched to authenticate the account. You should implement the appcontrol for the account provider.
For more details, see Account ProviderPrivilege level: public
Privilege: http://tizen.org/privilege/account.write
Parameters:
- account: Account object to be added.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; var provider = tizen.account.getProvider(appId); var account = new tizen.Account(provider, {userName: "admin", iconUri: "path/to/icon.jpg"}); tizen.account.add(account);
-
remove
-
Removes an account from the account database.
void remove(AccountId accountId);
Since: 5.0
Removes the account in the database that corresponds to the specified identifier. The function will throw an exception if it failed to remove the specified account.
This method can be used by an account provider application.
Privilege level: public
Privilege: http://tizen.org/privilege/account.write
Parameters:
- accountId: Identifier of the account to remove.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; tizen.account.getAccounts( function(accounts) { var account = accounts[0]; if (account) { tizen.account.remove(account.id); } }, function(e) { console.log("Error: " + e.message); }, appId);
-
update
-
Updates an account.
void update(Account account);
Since: 5.0
This method can be used only an account provider application.
Privilege level: public
Privilege: http://tizen.org/privilege/account.write
Parameters:
- account: Account object to update.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; tizen.account.getAccounts( function(accounts) { var account = accounts[0]; if (account) { account.userName = "abc"; tizen.account.update(account); } }, function(e) { console.log("Error: " + e.message); }, appId);
-
getAccount
-
Gets the Account object with the given identifier.
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- accountId: Account identifier.
Return value:
-
Account [nullable]:
Object with the given identifier or null.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var account = tizen.account.getAccount(1);
-
getAccounts
-
Gets the accounts associated with the provider that has a specified applicationId, asynchronously. If you want to get all accounts, omit the applicationId argument.
void getAccounts(AccountArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? applicationId);
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- successCallback: Callback method that is invoked when an asynchronous call completes successfully.
- errorCallback [optional] [nullable]: Callback method that is invoked when an error occurs.
- applicationId [optional] [nullable]: ApplicationId of the provider application.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
tizen.account.getAccounts( function(accounts) { /* Accounts is an array whose members are all registered accounts in this device. */ }, function(e) { console.log("Error: " + e.message); });
-
getProvider
-
Gets the account provider with the given application identifier.
AccountProvider? getProvider(ApplicationId applicationId);
Since: 5.0
You can register your application as an account provider by writing account related information in config.xml.
For more details, see Account ProviderPrivilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- applicationId: Identifier of the account provider application.
Return value:
-
AccountProvider [nullable]:
Object with the given applicationId or null.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var appId = tizen.application.getCurrentApplication().appInfo.id; var provider = tizen.account.getProvider(appId); if (!provider) { console.log("Current application is not account provider"); }
-
getProviders
-
Gets the providers with the given capabilities, asynchronously. If you want to get all the providers, omit the capability argument.
void getProviders(AccountProviderArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? capability);
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- successCallback: Callback method that is invoked when an asynchronous call completes successfully.
- errorCallback [optional] [nullable]: Callback method that is invoked when an error occurs.
- capability [optional] [nullable]: Predefined capability or the vendor-specific capability in IRI format.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
tizen.account.getProviders( function(providers) { /* Providers is an array whose members are account providers, */ /* which have contact capability. */ }, function(e) { console.log("Error: " + e.message); }, "http://tizen.org/account/capability/contact");
-
addAccountListener
-
Adds an account listener for watching changes to accounts.
long addAccountListener(AccountChangeCallback callback);
Since: 5.0
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- callback: Callback method that is invoked for the events about accounts such as adding or removing an account.
Return value:
-
long:
Identifier to clear the watch subscription for account changes.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
tizen.account.addAccountListener({ onadded: function(account) { /* Callback function which will be called when account is added. */ }, onremoved: function(accountId) { /* Callback function which will be called when account is removed. */ }, onupdated: function(account) { /* Callback function which will be called when account is updated. */ } });
-
removeAccountListener
-
Removes the previously registered listener.
void removeAccountListener(long accountListenerId);
Since: 5.0
Calling this function has no effect if there is no listener with given id.
Privilege level: public
Privilege: http://tizen.org/privilege/account.read
Parameters:
- accountListenerId: Identifier of the listener for the account changes.
Exceptions:
- WebAPIException
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var watchId = tizen.account.addAccountListener( { onadded: function(account) { /* Callback function which will be called when account is added. */ }, onremoved: function(accountId) { /* Callback function which will be called when account is removed. */ }, onupdated: function(account) { /* Callback function which will be called when account is updated. */ } }); tizen.account.removeAccountListener(watchId);
2.6. AccountExtendedData
[NoInterfaceObject] interface AccountExtendedData { readonly attribute DOMString key; readonly attribute DOMString value; };
Since: 5.0
Attributes
-
readonly
DOMString keyName (key) of the account extended data item.
Since: 2.3
-
readonly
DOMString valueValue of the account extended data item.
Since: 5.0
2.7. AccountArraySuccessCallback
[Callback, NoInterfaceObject] interface AccountArraySuccessCallback { void onsuccess(Account[] accounts); };
Since: 5.0
Methods
-
onsuccess
-
Called when information of accounts is ready.
void onsuccess(Account[] accounts);
Since: 5.0
Parameters:
- accounts: Received accounts.
2.8. AccountExtendedDataArraySuccessCallback
[Callback, NoInterfaceObject] interface AccountExtendedDataArraySuccessCallback { void onsuccess(AccountExtendedData[] extendedDataArray); };
Since: 5.0
Methods
-
onsuccess
-
Called when information of extended data is ready.
void onsuccess(AccountExtendedData[] extendedDataArray);
Since: 5.0
Parameters:
- extendedDataArray: Array of extended data.
2.9. AccountProviderArraySuccessCallback
[Callback, NoInterfaceObject] interface AccountProviderArraySuccessCallback { void onsuccess(AccountProvider[] providers); };
Since: 5.0
Methods
-
onsuccess
-
Called when information of providers are ready.
void onsuccess(AccountProvider[] providers);
Since: 5.0
Parameters:
- providers: Received providers.
2.10. AccountChangeCallback
[Callback, NoInterfaceObject] interface AccountChangeCallback { void onadded(Account account); void onremoved(AccountId accountId); void onupdated(Account account); };
Since: 5.0
Methods
-
onadded
-
Called when an account is added.
void onadded(Account account);
Since: 5.0
Parameters:
- account: Added account information.
-
onremoved
-
Called when an account is removed.
void onremoved(AccountId accountId);
Since: 5.0
Parameters:
- accountId: ID of the removed account.
-
onupdated
-
Called when an account is updated.
void onupdated(Account account);
Since: 5.0
Parameters:
- account: Updated account information.
3. Related Feature
To guarantee the running of the application on a device with Account feature, declare the following feature requirement in the config file:
4. Full WebIDL
module Account { typedef unsigned long AccountId; dictionary AccountInit { DOMString userName; DOMString iconUri; }; Tizen implements AccountManagerObject; [NoInterfaceObject] interface AccountManagerObject { readonly attribute AccountManager account; }; [NoInterfaceObject] interface AccountProvider { readonly attribute ApplicationId applicationId; readonly attribute DOMString displayName; readonly attribute DOMString iconUri; readonly attribute DOMString smallIconUri; readonly attribute DOMString[] capabilities; readonly attribute boolean isMultipleAccountSupported; }; [Constructor(AccountProvider provider, optional AccountInit? accountInitDict)] interface Account { readonly attribute AccountId? id; attribute DOMString? userName; attribute DOMString? iconUri; readonly attribute AccountProvider provider; void setExtendedData(DOMString key, DOMString value) raises(WebAPIException); DOMString getExtendedData(DOMString key) raises(WebAPIException); void getExtendedData(AccountExtendedDataArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface AccountManager { void add(Account account) raises(WebAPIException); void remove(AccountId accountId) raises(WebAPIException); void update(Account account) raises(WebAPIException); Account? getAccount(AccountId accountId) raises(WebAPIException); void getAccounts(AccountArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? applicationId) raises(WebAPIException); AccountProvider? getProvider(ApplicationId applicationId) raises(WebAPIException); void getProviders(AccountProviderArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional DOMString? capability) raises(WebAPIException); long addAccountListener(AccountChangeCallback callback) raises(WebAPIException); void removeAccountListener(long accountListenerId) raises(WebAPIException); }; [NoInterfaceObject] interface AccountExtendedData { readonly attribute DOMString key; readonly attribute DOMString value; }; [Callback, NoInterfaceObject] interface AccountArraySuccessCallback { void onsuccess(Account[] accounts); }; [Callback, NoInterfaceObject] interface AccountExtendedDataArraySuccessCallback { void onsuccess(AccountExtendedData[] extendedDataArray); }; [Callback, NoInterfaceObject] interface AccountProviderArraySuccessCallback { void onsuccess(AccountProvider[] providers); }; [Callback, NoInterfaceObject] interface AccountChangeCallback { void onadded(Account account); void onremoved(AccountId accountId); void onupdated(Account account); }; };