diff --git a/en/application-dev/reference/apis/js-apis-appAccount.md b/en/application-dev/reference/apis/js-apis-appAccount.md index c98d603c0092e8f2fd9e1f9a2ce0d33ecd9cc1a7..5814fad2cff1b347469cc49c6a51196e9beb1e80 100644 --- a/en/application-dev/reference/apis/js-apis-appAccount.md +++ b/en/application-dev/reference/apis/js-apis-appAccount.md @@ -1,8 +1,9 @@ # App Account Management -The **appAccount** module provides APIs for app account management. You can use the APIs to add, delete, query, modify, and authorize app accounts, write data to disks, and synchronize data. +The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app authentication and distributed data synchronization. -> **NOTE**
+> **NOTE** +> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -17,7 +18,7 @@ import account_appAccount from '@ohos.account.appAccount'; createAppAccountManager(): AppAccountManager -Creates an **AppAccountManager** instance. +Creates an **AppAccountManager** object. **System capability**: SystemCapability.Account.AppAccount @@ -25,46 +26,59 @@ Creates an **AppAccountManager** instance. | Type | Description | | ----------------- | ------------ | -| AppAccountManager | **AppAccountManager** instance created.| +| AppAccountManager | **AppAccountManager** object created.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); + let appAccountManager = account_appAccount.createAppAccountManager(); ``` ## AppAccountManager -Provides methods to manage app accounts. +Implements app account management. -### addAccount +### createAccount9+ -addAccount(name: string, callback: AsyncCallback<void>): void +createAccount(name: string, callback: AsyncCallback<void>): void; -Adds an app account to the **AppAccountManager** service. This API uses an asynchronous callback to return the result. +Creates an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | -------------------- | -| name | string | Yes | Name of the app account to add. | -| callback | AsyncCallback<void> | Yes | Callback invoked when the app account is added.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ----- | -------------------- | +| name | string | Yes | Name of the app account to create. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300004 | Account already exists. | +| 12300007 | The number of accounts reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("WangWu", (err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.createAccount("WangWu", (err) => { + console.log("createAccount err: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("createAccount err: " + JSON.stringify(err)); + } ``` -### addAccount +### createAccount9+ -addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void +createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void -Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses an asynchronous callback to return the result. +Creates an app account with custom data. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -72,26 +86,46 @@ Adds an app account name and additional information (information that can be con | Name | Type | Mandatory | Description | | --------- | ------------------------- | ---- | ---------------------------------------- | -| name | string | Yes | Name of the app account to add. | -| extraInfo | string | Yes | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.| -| callback | AsyncCallback<void> | Yes | Callback invoked when the app account name and additional information are added. | +| name | string | Yes | Name of the app account to create. | +| options | [CreateAccountOptions](#createaccountoptions9) | Yes | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens).| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or options. | +| 12300004 | Account already exists. | +| 12300007 | The number of accounts reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("LiSi", "token101", (err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + customData: { + "age": "10" + } + } + try { + appAccountManager.createAccount("LiSi", options, (err) => { + if (err) { + console.log("createAccount failed, error: " + JSON.stringify(err)); + } else { + console.log("createAccount successfully"); + } + }); + } catch(err) { + console.log("createAccount exception: " + JSON.stringify(err)); + } ``` +### createAccount9+ +createAccount(name: string, options?: CreateAccountOptions): Promise<void> -### addAccount - -addAccount(name: string, extraInfo?: string): Promise<void> - -Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses a promise to return the result. +Creates an app account with custom data. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -99,31 +133,104 @@ Adds an app account name and additional information (information that can be con | Name | Type | Mandatory | Description | | --------- | ------ | ---- | ---------------------------------------- | -| name | string | Yes | Name of the app account to add. | -| extraInfo | string | No | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.| +| name | string | Yes | Name of the app account to create. | +| options | [CreateAccountOptions](#createaccountoptions9) | No | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens). This parameter can be left empty.| **Return value** | Type | Description | | ------------------- | --------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or options. | +| 12300004 | Account already exists. | +| 12300007 | The number of accounts reaches the upper limit. | +| 12400003 | The number of custom data reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccount("LiSi", "token101").then(()=> { - console.log('addAccount Success'); - }).catch((err) => { - console.log("addAccount err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + customData: { + "age": "10" + } + } + try { + appAccountManager.createAccount("LiSi", options).then(() => { + console.log("createAccount successfully"); + }).catch((err) => { + console.log("createAccount failed, error: " + JSON.stringify(err)); + }); + } catch(err) { + console.log("createAccount exception: " + JSON.stringify(err)); + } ``` -### addAccountImplicitly8+ +### createAccountImplicitly9+ -addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void +createAccountImplicitly(owner: string, callback: AuthCallback): void + +Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ---- | ----------------------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12300007 | The number of accounts reaches the upper limit. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + import featureAbility from '@ohos.ability.featureAbility'; -Implicitly adds an app account based on the specified account owner, authentication type, and options. This API uses an asynchronous callback to return the result. + function onResultCallback(code, result) { + console.log("resultCode: " + code); + console.log("result: " + JSON.stringify(result)); + } + + function onRequestRedirectedCallback(request) { + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err) => { + console.log("startAbility err: " + JSON.stringify(err)); + }); + } + + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.createAccountImplicitly("com.example.accountjsdemo", { + onResult: onResultCallback, + onRequestRedirected: onRequestRedirectedCallback + }); + } catch (err) { + console.log("createAccountImplicitly exception: " + JSON.stringify(err)); + } + ``` + +### createAccountImplicitly9+ + +createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void + +Creates an app account implicitly based on the specified account owner and options. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -131,10 +238,20 @@ Implicitly adds an app account based on the specified account owner, authenticat | Name | Type | Mandatory | Description | | -------- | --------------------- | ---- | ----------------------- | -| owner | string | Yes | Owner of the app account to add. The value is the bundle name of the app. | -| authType | string | Yes | Authentication type of the app account to add. The authentication type is customized. | -| options | {[key: string]: any} | Yes | Authentication options, which can be set as required.| -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the authentication result. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or options. | +| 12300007 | The number of accounts reaches the upper limit. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | **Example** @@ -142,29 +259,37 @@ Implicitly adds an app account based on the specified account owner, authenticat import featureAbility from '@ohos.ability.featureAbility'; function onResultCallback(code, result) { - console.log("resultCode: " + code); - console.log("result: " + JSON.stringify(result)); + console.log("resultCode: " + code); + console.log("result: " + JSON.stringify(result)); } function onRequestRedirectedCallback(request) { - let abilityStartSetting = {want: request}; - featureAbility.startAbility(abilityStartSetting, (err)=>{ - console.log("startAbility err: " + JSON.stringify(err)); - }); + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err) => { + console.log("startAbility err: " + JSON.stringify(err)); + }); } - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.addAccountImplicitly("com.example.ohos.accountjsdemo", "getSocialData", {}, { + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + authType: "getSocialData", + requiredLabels: [ "student" ] + }; + try { + appAccountManager.createAccountImplicitly("com.example.accountjsdemo", options, { onResult: onResultCallback, onRequestRedirected: onRequestRedirectedCallback - }); + }); + } catch (err) { + console.log("createAccountImplicitly exception: " + JSON.stringify(err)); + } ``` -### deleteAccount +### removeAccount9+ -deleteAccount(name: string, callback: AsyncCallback<void>): void +removeAccount(name: string, callback: AsyncCallback<void>): void -Deletes an app account from the **AppAccountManager** service. This API uses an asynchronous callback to return the result. +Removes an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -172,23 +297,39 @@ Deletes an app account from the **AppAccountManager** service. This API uses an | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ---------------- | -| name | string | Yes | Name of the app account to delete. | -| callback | AsyncCallback<void> | Yes | Callback invoked when the app account is deleted.| +| name | string | Yes | Name of the app account to remove. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccount("ZhaoLiu", (err) => { - console.log("deleteAccount err: " + JSON.stringify(err)); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.removeAccount("ZhaoLiu", (err) => { + if (err) { + console.log("removeAccount failed, error: " + JSON.stringify(err)); + } else { + console.log("removeAccount successfully"); + } }); + } catch(err) { + console.log("removeAccount exception: " + JSON.stringify(err)); + } ``` -### deleteAccount +### removeAccount9+ -deleteAccount(name: string): Promise<void> +removeAccount(name: string): Promise<void> -Deletes an app account from the **AppAccountManager** service. This API uses a promise to return the result. +Removes an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -196,87 +337,131 @@ Deletes an app account from the **AppAccountManager** service. This API uses a p | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ----------- | -| name | string | Yes | Name of the app account to delete.| +| name | string | Yes | Name of the app account to remove.| **Return value** | Type | Description | | :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccount("ZhaoLiu").then(() => { - console.log('deleteAccount Success'); - }).catch((err) => { - console.log("deleteAccount err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.removeAccount("Lisi").then(() => { + console.log("removeAccount successfully"); + }).catch((err) => { + console.log("removeAccount failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("removeAccount exception: " + JSON.stringify(err)); + } ``` -### disableAppAccess +### setAppAccess9+ -disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void +setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void -Disables an app account from accessing an app with the given bundle name. This API uses an asynchronous callback to return the result. +Sets the access to the data of an account for an app. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ------------------------- | ---- | --------------------------------- | -| name | string | Yes | Name of the target app account. | -| bundleName | string | Yes | Bundle name of the app. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| ------------ | ------------------------- | ---- | --------------------------------- | +| name | string | Yes | Name of the target app account. | +| bundleName | string | Yes | Bundle name of the app. | +| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or bundleName. | +| 12300003 | Account not found. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { - console.log("disableAppAccess err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true, (err) => { + if (err) { + console.log("setAppAccess failed: " + JSON.stringify(err)); + } else { + console.log("setAppAccess successfully"); + } + }); + } catch (err) { + console.log("setAppAccess exception: " + JSON.stringify(err)); + } ``` -### disableAppAccess +### setAppAccess9+ -disableAppAccess(name: string, bundleName: string): Promise<void> +setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void> -Disables an app account from accessing an app with the given bundle name. This API uses a promise to return the result. +Sets the access to the data of an account for an app. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ------ | ---- | ---------------- | -| name | string | Yes | Name of the target app account.| -| bundleName | string | Yes | Bundle name of the app. | +| Name | Type | Mandatory | Description | +| ---------- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| bundleName | string | Yes | Bundle name of the app.| +| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| **Return value** | Type | Description | | :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or bundleName. | +| 12300003 | Account not found. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { - console.log('disableAppAccess Success'); - }).catch((err) => { - console.log("disableAppAccess err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true).then(() => { + console.log("setAppAccess successfully"); + }).catch((err) => { + console.log("setAppAccess failed: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setAppAccess exception: " + JSON.stringify(err)); + } ``` -### enableAppAccess +### checkAppAccess9+ -enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void +checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void -Enables an app account to access an app with the given bundle name. This API uses an asynchronous callback to return the result. +Checks whether an app can access the data of an account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -286,22 +471,39 @@ Enables an app account to access an app with the given bundle name. This API use | ---------- | ------------------------- | ---- | --------------------------------- | | name | string | Yes | Name of the target app account. | | bundleName | string | Yes | Bundle name of the app. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or bundleName. | +| 12300003 | Account not found. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { - console.log("enableAppAccess: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo", (err, isAccessible) => { + if (err) { + console.log("checkAppAccess failed, error: " + JSON.stringify(err)); + } else { + console.log("checkAppAccess successfully"); + } + }); + } catch (err) { + console.log("checkAppAccess exception: " + JSON.stringify(err)); + } ``` -### enableAppAccess +### checkAppAccess9+ -enableAppAccess(name: string, bundleName: string): Promise<void> +checkAppAccess(name: string, bundleName: string): Promise<boolean> -Enables an app account to access an app with the given bundle name. This API uses a promise to return the result. +Checks whether an app can access the data of an account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -314,26 +516,124 @@ Enables an app account to access an app with the given bundle name. This API use **Return value** +| Type | Description | +| ------------------- | --------------------- | +| Promise<boolean> | Promise used to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or bundleName. | +| 12300003 | Account not found. | +| 12400001 | Application not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo").then((isAccessible) => { + console.log("checkAppAccess successfully, isAccessible: " + isAccessible); + }).catch((err) => { + console.log("checkAppAccess failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("checkAppAccess exception: " + JSON.stringify(err)); + } + ``` + +### setDataSyncEnabled9+ + +setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void + +Sets data synchronization for an app account. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------- | +| name | string | Yes | Name of the target app account. | +| isEnabled | boolean | Yes | Whether to enable data synchronization. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setDataSyncEnabled("ZhangSan", true, (err) => { + console.log("setDataSyncEnabled err: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setDataSyncEnabled err: " + JSON.stringify(err)); + } + ``` + +### setDataSyncEnabled9+ + +setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void> + +Sets data synchronization for an app account. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------- | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| isEnabled | boolean | Yes | Whether to enable data synchronization.| + +**Return value** + | Type | Description | | :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { - console.log('enableAppAccess Success'); - }).catch((err) => { - console.log("enableAppAccess err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager .setDataSyncEnabled("ZhangSan", true).then(() => { + console.log('setDataSyncEnabled Success'); + }).catch((err) => { + console.log("setDataSyncEnabled err: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setDataSyncEnabled err: " + JSON.stringify(err)); + } ``` -### checkAppAccountSyncEnable +### checkDataSyncEnabled9+ -checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void +checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void -Checks whether an app account allows app data synchronization. This API uses an asynchronous callback to return the result. +Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC @@ -344,23 +644,38 @@ Checks whether an app account allows app data synchronization. This API uses an | Name | Type | Mandatory | Description | | -------- | ---------------------------- | ---- | --------------------- | | name | string | Yes | Name of the target app account. | -| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { - console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); - console.log('checkAppAccountSyncEnable result: ' + result); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkDataSyncEnabled("ZhangSan", (err, isEnabled) => { + if (err) { + console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err)); + } else { + console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled); + } + }); + } catch (err) { + console.log("checkDataSyncEnabled err: " + JSON.stringify(err)); + } ``` -### checkAppAccountSyncEnable +### checkDataSyncEnabled9+ -checkAppAccountSyncEnable(name: string): Promise<boolean> +checkDataSyncEnabled(name: string): Promise<boolean> -Checks whether an app account allows app data synchronization. This API uses a promise to return the result. +Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC @@ -376,22 +691,34 @@ Checks whether an app account allows app data synchronization. This API uses a p | Type | Description | | :--------------------- | :-------------------- | -| Promise<boolean> | Promise used to return the result.| +| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { - console.log('checkAppAccountSyncEnable, result: ' + data); - }).catch((err) => { - console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkDataSyncEnabled("ZhangSan").then((isEnabled) => { + console.log("checkDataSyncEnabled successfully, isEnabled: " + isEnabled); + }).catch((err) => { + console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("checkDataSyncEnabled err: " + JSON.stringify(err)); + } ``` -### setAccountCredential +### setCredential9+ -setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void +setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void Sets a credential for an app account. This API uses an asynchronous callback to return the result. @@ -403,21 +730,37 @@ Sets a credential for an app account. This API uses an asynchronous callback to | -------------- | ------------------------- | ---- | ------------- | | name | string | Yes | Name of the target app account. | | credentialType | string | Yes | Type of the credential to set. | -| credential | string | Yes | Credential to set. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| credential | string | Yes | Credential value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the credential is set successfully, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType or credential. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { - console.log("setAccountCredential err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx", (err) => { + if (err) { + console.log("setCredential failed, error: " + JSON.stringify(err)); + } else { + console.log("setCredential successfully"); + } + }); + } catch (err) { + console.log("setCredential exception: " + JSON.stringify(err)); + } ``` -### setAccountCredential +### setCredential9+ -setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> +setCredential(name: string, credentialType: string, credential: string): Promise<void> Sets a credential for an app account. This API uses a promise to return the result. @@ -429,587 +772,648 @@ Sets a credential for an app account. This API uses a promise to return the resu | -------------- | ------ | ---- | ---------- | | name | string | Yes | Name of the target app account. | | credentialType | string | Yes | Type of the credential to set.| -| credential | string | Yes | Credential to set. | +| credential | string | Yes | Credential value. | **Return value** -| Type | Description | +| Type | Description | | :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType or credential. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { - console.log('setAccountCredential Success'); - }).catch((err) => { - console.log("setAccountCredential err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx").then(() => { + console.log("setCredential successfully"); + }).catch((err) => { + console.log("setCredential failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setCredential exception: " + JSON.stringify(err)); + } ``` -### setAccountExtraInfo +### getCredential9+ -setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void +getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void -Sets additional information for an app account. This API uses an asynchronous callback to return the result. +Obtains the credential of an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| --------- | ------------------------- | ---- | --------------- | -| name | string | Yes | Name of the target app account. | -| extraInfo | string | Yes | Additional information to set. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| Name | Type | Mandatory | Description | +| -------------- | --------------------------- | ---- | -------------- | +| name | string | Yes | Name of the target app account. | +| credentialType | string | Yes | Type of the credential to obtain.| +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType. | +| 12300003 | Account not found. | +| 12300102 | Credential not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { - console.log("setAccountExtraInfo err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getCredential("ZhangSan", "PIN_SIX", (err, result) => { + if (err) { + console.log("getCredential failed, error: " + JSON.stringify(err)); + } else { + console.log('getCredential successfully, result: ' + result); + } + }); + } catch (err) { + console.log("getCredential err: " + JSON.stringify(err)); + } ``` -### setAccountExtraInfo +### getCredential9+ -setAccountExtraInfo(name: string, extraInfo: string): Promise<void> +getCredential(name: string, credentialType: string): Promise<string> -Sets additional information for an app account. This API uses a promise to return the result. +Obtains the credential of an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| --------- | ------ | ---- | --------- | -| name | string | Yes | Name of the target app account. | -| extraInfo | string | Yes | Additional information to set.| +| Name | Type | Mandatory | Description | +| -------------- | ------ | ---- | ---------- | +| name | string | Yes | Name of the target app account.| +| credentialType | string | Yes | Type of the credential to obtain.| **Return value** -| Type | Description | -| :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Type | Description | +| :-------------------- | :-------------------- | +| Promise<string> | Promise used to return the credential obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType. | +| 12300003 | Account not found. | +| 12300102 | Credential not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { - console.log('setAccountExtraInfo Success'); - }).catch((err) => { - console.log("setAccountExtraInfo err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getCredential("ZhangSan", "PIN_SIX").then((credential) => { + console.log("getCredential successfully, credential: " + credential); + }).catch((err) => { + console.log("getCredential failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getCredential exception: " + JSON.stringify(err)); + } ``` -### setAppAccountSyncEnable - -setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void +### setCustomData9+ -Sets whether to enable app data synchronization for an app account. This API uses an asynchronous callback to return the result. +setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void -**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC +Sets custom data for an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ------------------------- | -| name | string | Yes | Name of the target app account. | -| isEnable | boolean | Yes | Whether to enable app data synchronization. | -| callback | AsyncCallback<void> | Yes | Callback invoked when app data synchronization is enabled or disabled for the app account.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------------- | +| name | string | Yes | Name of the target app account.| +| key | string | Yes | Key of the custom data to set.| +| value | string | Yes | Value of the custom data to set.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or key or value. | +| 12300003 | Account not found. | +| 12400003 | The number of custom data reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { - console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setCustomData("ZhangSan", "age", "12", (err) => { + if (err) { + console.log("setCustomData failed, error: " + JSON.stringify(err)); + } else { + console.log("setCustomData successfully"); + } + }); + } catch (err) { + console.log("setCustomData exception: " + JSON.stringify(err)); + } ``` -### setAppAccountSyncEnable - -setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> +### setCustomData9+ -Sets whether to enable app data synchronization for an app account. This API uses a promise to return the result. +setCustomData(name: string, key: string, value: string): Promise<void> -**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC +Sets custom data for an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------- | ---- | ----------- | -| name | string | Yes | Name of the target app account. | -| isEnable | boolean | Yes | Whether to enable app data synchronization.| +| Name | Type| Mandatory | Description | +| ----- | ------ | ---- | ----------------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the custom data to set.| +| value | string | Yes | Value of the custom data to set.| **Return value** | Type | Description | | :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or key or value. | +| 12300003 | Account not found. | +| 12400003 | The number of custom data reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { - console.log('setAppAccountSyncEnable Success'); - }).catch((err) => { - console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setCustomData("ZhangSan", "age", "12").then(() => { + console.log("setCustomData successfully"); + }).catch((err) => { + console.log("setCustomData failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setCustomData exception: " + JSON.stringify(err)); + } ``` -### setAssociatedData +### getCustomData9+ -setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void +getCustomData(name: string, key: string, callback: AsyncCallback<string>): void -Sets data to be associated with an app account. This API uses an asynchronous callback to return the result. +Obtains the custom data of an app account based on the specified key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | ---- | ----------------- | -| name | string | Yes | Name of the target app account. | -| key | string | Yes | Key of the data to set. The private key can be customized.| -| value | string | Yes | Value of the data to be set. | -| callback | AsyncCallback<void> | Yes | Callback invoked when the data associated with the specified app account is set.| +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ----- | ------------------------ | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the custom data to obtain. | +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the custom data value obtained. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or key. | +| 12300003 | Account not found. | +| 12400002 | Custom data not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => { - console.log("setAssociatedData err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getCustomData("ZhangSan", "age", (err, data) => { + if (err) { + console.log('getCustomData failed, error: ' + err); + } else { + console.log("getCustomData successfully, data: " + data); + } + }); + } catch (err) { + console.log("getCustomData exception: " + JSON.stringify(err)); + } ``` -### setAssociatedData +### getCustomData9+ -setAssociatedData(name: string, key: string, value: string): Promise<void> +getCustomData(name: string, key: string): Promise<string> -Sets data to be associated with an app account. This API uses a promise to return the result. +Obtains the custom data of an app account based on the specified key. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----------------- | -| name | string | Yes | Name of the target app account. | -| key | string | Yes | Key of the data to set. The private key can be customized.| -| value | string | Yes | Value of the data to be set. | +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the custom data to obtain.| **Return value** -| Type | Description | -| :------------------ | :-------------------- | -| Promise<void> | Promise used to return the result.| +| Type | Description | +| --------------------- | --------------------- | +| Promise<string> | Promise used to return the custom data value obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or key. | +| 12300003 | Account not found. | +| 12400002 | Custom data not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { - console.log('setAssociatedData Success'); - }).catch((err) => { - console.log("setAssociatedData err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getCustomData("ZhangSan", "age").then((data) => { + console.log("getCustomData successfully, data: " + data); + }).catch((err) => { + console.log("getCustomData failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getCustomData exception: " + JSON.stringify(err)); + } ``` -### getAccountCredential +### getCustomDataSync9+ -getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void +getCustomDataSync(name: string, key: string): string; -Obtains the credentials (such as the digital password, face image, and PIN) of an app account. This API uses an asynchronous callback to return the result. +Obtains the custom data of an app account based on the specified key. The API returns the result synchronously. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | --------------------------- | ---- | -------------- | -| name | string | Yes | Name of the target app account. | -| credentialType | string | Yes | Type of the credential to obtain.| -| callback | AsyncCallback<string> | Yes | Callback invoked to return the credential obtained.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the custom data to obtain.| + +**Return value** + +| Type | Description | +| --------------------- | --------------------- | +| string | Value of the custom data obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or key. | +| 12300003 | Account not found. | +| 12400002 | Custom data not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { - console.log("getAccountCredential err: " + JSON.stringify(err)); - console.log('getAccountCredential result: ' + result); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + let value = appAccountManager.getCustomDataSync("ZhangSan", "age"); + console.info("getCustomDataSync successfully, vaue:" + value); + } catch (err) { + console.error("getCustomDataSync failed, error: " + JSON.stringify(err)); + } ``` -### getAccountCredential +### getAllAccounts9+ -getAccountCredential(name: string, credentialType: string): Promise<string> +getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void -Obtains the credential of an app account. This API uses a promise to return the result. +Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------ | ---- | ---------- | -| name | string | Yes | Name of the target app account. | -| credentialType | string | Yes | Type of the credential to obtain.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | --------- | +| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.| -**Return value** +**Error codes** -| Type | Description | -| :-------------------- | :-------------------- | -| Promise<string> | Promise used to return the result.| +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { - console.log('getAccountCredential, result: ' + data); - }).catch((err) => { - console.log("getAccountCredential err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAllAccounts((err, data) => { + if (err) { + console.debug("getAllAccounts failed, error:" + JSON.stringify(err)); + } else { + console.debug("getAllAccounts successfully"); + } + }); + } catch (err) { + console.debug("getAllAccounts exception: " + JSON.stringify(err)); + } ``` -### getAccountExtraInfo +### getAllAccounts9+ -getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void +getAllAccounts(): Promise<Array<AppAccountInfo>> + +Obtains information about all accessible app accounts. This API uses a promise to return the result. -Obtains additional information (information that can be converted into the string type) about an app account. This API uses an asynchronous callback to return the result. +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS **System capability**: SystemCapability.Account.AppAccount -**Parameters** +**Return value** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | --------------- | -| name | string | Yes | Name of the target app account. | -| callback | AsyncCallback<string> | Yes | Callback invoked to return the additional information of the specified app account.| +| Type | Description | +| ---------------------------------------- | --------------------- | +| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return information about all accessible accounts.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { - console.log("getAccountExtraInfo err: " + JSON.stringify(err)); - console.log('getAccountExtraInfo result: ' + result); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAllAccounts().then((data) => { + console.debug("getAllAccounts successfully"); + }).catch((err) => { + console.debug("getAllAccounts failed, error:" + JSON.stringify(err)); + }); + } catch (err) { + console.debug("getAllAccounts exception: " + JSON.stringify(err)); + } ``` -### getAccountExtraInfo +### getAccountsByOwner9+ -getAccountExtraInfo(name: string): Promise<string> +getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void + +Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result. -Obtains additional information of an app account. This API uses a promise to return the result. +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | ------- | -| name | string | Yes | Name of the target app account.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | --------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is null and **data** is the app account information obtained. Otherwise, **err** is an error object.| -**Return value** +**Error codes** -| Type | Description | -| :-------------------- | :-------------------- | -| Promise<string> | Promise used to return the result.| +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { - console.log('getAccountExtraInfo, result: ' + data); - }).catch((err) => { - console.log("getAccountExtraInfo err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAccountsByOwner("com.example.accountjsdemo2", (err, data) => { + if (err) { + console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err)); + } else { + console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data)); + } + }); + } catch (err) { + console.debug("getAccountsByOwner exception:" + JSON.stringify(err)); + } ``` -### getAssociatedData +### getAccountsByOwner9+ -getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void +getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>> -Obtains data associated with an app account. This API uses an asynchronous callback to return the result. +Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ----------------- | -| name | string | Yes | Name of the target app account. | -| key | string | Yes | Key of the data to obtain. | -| callback | AsyncCallback<string> | Yes | Callback invoked to return the data associated with the specified app account.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ------ | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| + +**Return value** + +| Type | Description | +| ---------------------------------------- | --------------------- | +| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the app account information obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { - console.log("getAssociatedData err: " + JSON.stringify(err)); - console.log('getAssociatedData result: ' + result); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAccountsByOwner("com.example.accountjsdemo2").then((data) => { + console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data)); + }).catch((err) => { + console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err)); + }); + } catch (err) { + console.debug("getAccountsByOwner exception:" + JSON.stringify(err)); + } ``` -### getAssociatedData +### on('accountChange')9+ -getAssociatedData(name: string, key: string): Promise<string> +on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void -Obtains data associated with an app account. This API uses a promise to return the result. +Subscribes to account information changes of apps. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | --------- | -| name | string | Yes | Name of the target app account. | -| key | string | Yes | Key of the data to obtain.| +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ------------------------------ | +| type | 'accountChange' | Yes | Event type to subscribe to. The value is **'accountChange'**. An event will be reported when the account information of the target app changes.| +| owners | Array<string> | Yes | App bundle names of the account. | +| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return a list of app accounts whose information is changed. | -**Return value** +**Error codes** -| Type | Description | -| :-------------------- | :-------------------- | -| Promise<string> | Promise used to return the result.| +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid type or owners. | +| 12300011 | Callback has been registered. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { - console.log('getAssociatedData: ' + data); - }).catch((err) => { - console.log("getAssociatedData err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + function changeOnCallback(data){ + console.log("receive change data:" + JSON.stringify(data)); + } + try{ + appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback); + } catch(err) { + console.error("on accountChange failed, error:" + JSON.stringify(err)); + } ``` -### getAssociatedDataSync9+ +### off('accountChange')9+ -getAssociatedDataSync(name: string, key: string): string; +off(type: 'accountChange', callback?: Callback>): void -Obtains the data associated with this app account. This API returns the result synchronously. +Unsubscribes from account information changes. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | ---- | --------- | -| name | string | Yes | Name of the target app account. | -| key | string | Yes | Key of the data to obtain.| +| Name | Type | Mandatory | Description | +| -------- | -------------------------------- | ---- | ------------ | +| type | 'accountChange' | Yes | Event type to unsubscribe from. The value is **'accountChange'**. | +| callback | Callback> | No | Callback to unregister.| -**Return value** +**Error codes** -| Type | Description | -| :-------------------- | :-------------------- | -| string | Data obtained.| +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid type. | +| 12300012 | Callback has not been registered. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var backData = appAccountManager.getAssociatedDataSync("ZhangSan", "k001"); - console.info("getAssociatedDataSync backData:" + JSON.stringify(backData)); + let appAccountManager = account_appAccount.createAppAccountManager(); + function changeOnCallback(data){ + console.log("receive change data:" + JSON.stringify(data)); + } + try{ + appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback); + } catch(err) { + console.error("on accountChange failed, error:" + JSON.stringify(err)); + } + try{ + appAccountManager.off('accountChange', changeOnCallback); + } + catch(err){ + console.error("off accountChange failed, error:" + JSON.stringify(err)); + } ``` -### getAllAccessibleAccounts - -getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void +### auth9+ -Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. +auth(name: string, owner: string, authType: string, callback: AuthCallback): void -**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) +Authenticates an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | --------- | -| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return information about all accessible app accounts.| +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ---- | --------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| authType | string | Yes | Authentication type. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the authentication result.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or authType. | +| 12300003 | Account not found. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllAccessibleAccounts((err, data)=>{ - console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err)); - console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data)); - }); - ``` + import featureAbility from '@ohos.ability.featureAbility'; -### getAllAccessibleAccounts + function onResultCallback(code, authResult) { + console.log("resultCode: " + code); + console.log("authResult: " + JSON.stringify(authResult)); + } -getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> + function onRequestRedirectedCallback(request) { + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err) => { + console.log("startAbility err: " + JSON.stringify(err)); + }); + } -Obtains information about all accessible app accounts. This API uses a promise to return the result. + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", { + onResult: onResultCallback, + onRequestRedirected: onRequestRedirectedCallback + }); + } catch (err) { + console.log("auth exception: " + JSON.stringify(err)); + } + ``` -**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) +### auth9+ -**System capability**: SystemCapability.Account.AppAccount +auth(name: string, owner: string, authType: string, options: {[key: string]: Object}, callback: AuthCallback): void -**Parameters** - -| Type | Description | -| ---------------------------------------- | --------------------- | -| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the result.| - -**Example** - - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllAccessibleAccounts().then((data) => { - console.log('getAllAccessibleAccounts: ' + data); - }).catch((err) => { - console.log("getAllAccessibleAccounts err: " + JSON.stringify(err)); - }); - ``` - -### getAllAccounts - -getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void - -Obtains information about all app accounts of the specified app. This API uses an asynchronous callback to return the result. - -**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) - -**System capability**: SystemCapability.Account.AppAccount - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | --------- | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | -| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return information about all accessible app accounts.| - -**Example** - - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - const selfBundle = "com.example.actsgetallaaccounts"; - appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ - console.debug("getAllAccounts err:" + JSON.stringify(err)); - console.debug("getAllAccounts data:" + JSON.stringify(data)); - }); - ``` - -### getAllAccounts - -getAllAccounts(owner: string): Promise<Array<AppAccountInfo>> - -Obtains information about all app accounts of the specified app. This API uses a promise to return the result. - -**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) - -**System capability**: SystemCapability.Account.AppAccount - -**Parameters** - -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ------ | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| - -**Parameters** - -| Type | Description | -| ---------------------------------------- | --------------------- | -| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the result.| - -**Example** - - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - const selfBundle = "com.example.actsgetallaaccounts"; - appAccountManager.getAllAccounts(selfBundle).then((data) => { - console.log('getAllAccounts: ' + data); - }).catch((err) => { - console.log("getAllAccounts err: " + JSON.stringify(err)); - }); - ``` - -### on('change') - -on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void - -Subscribes to the account change events of the specified account owners. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Account.AppAccount - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ------------------------------ | -| type | 'change' | Yes | Account change events to subscribe to. The subscriber will receive a notification when the account owners update their accounts.| -| owners | Array<string> | Yes | Account owners. | -| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the account changes. | - -**Example** - - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - function changeOnCallback(data){ - console.debug("receive change data:" + JSON.stringify(data)); - } - try{ - appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); - } - catch(err){ - console.error("on accountOnOffDemo err:" + JSON.stringify(err)); - } - ``` - -### off('change') - -off(type: 'change', callback?: Callback>): void - -Unsubscribes from the account change events. This API uses an asynchronous callback to return the result. - -**System capability**: SystemCapability.Account.AppAccount - -**Parameters** - -| Name | Type | Mandatory | Description | -| -------- | -------------------------------- | ---- | ------------ | -| type | 'change' | Yes | Account change events to unsubscribe from. | -| callback | Callback> | No | Callback used to report the account changes.| - -**Example** - - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - function changeOnCallback(data){ - console.debug("receive change data:" + JSON.stringify(data)); - appAccountManager.off('change', function(){ - console.debug("off finish"); - }) - } - try{ - appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); - } - catch(err){ - console.error("on accountOnOffDemo err:" + JSON.stringify(err)); - } - ``` - -### authenticate8+ - -authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void - -Authenticates an app account to obtain an Open Authorization (OAuth) token. This API uses an asynchronous callback to return the result. +Authenticates an app account with customized options. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1020,38 +1424,56 @@ Authenticates an app account to obtain an Open Authorization (OAuth) token. This | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | | authType | string | Yes | Authentication type. | -| options | {[key: string]: any} | Yes | Options for the authentication. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the authentication result.| +| options | {[key: string]: Object} | Yes | Options for the authentication. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the authentication result.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or authType. | +| 12300003 | Account not exist. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | **Example** ```js import featureAbility from '@ohos.ability.featureAbility'; - function onResultCallback(code, result) { - console.log("resultCode: " + code); - console.log("result: " + JSON.stringify(result)); + function onResultCallback(code, authResult) { + console.log("resultCode: " + code); + console.log("authResult: " + JSON.stringify(authResult)); } function onRequestRedirectedCallback(request) { - let abilityStartSetting = {want: request}; - featureAbility.startAbility(abilityStartSetting, (err)=>{ - console.log("startAbility err: " + JSON.stringify(err)); - }); + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err) => { + console.log("startAbility err: " + JSON.stringify(err)); + }); } - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", {}, { - onResult: onResultCallback, - onRequestRedirected: onRequestRedirectedCallback - }); + let options = { + "password": "xxxx", + }; + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", options, { + onResult: onResultCallback, + onRequestRedirected: onRequestRedirectedCallback + }); + } catch (err) { + console.log("auth exception: " + JSON.stringify(err)); + } ``` -### getOAuthToken8+ +### getAuthToken9+ -getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void +getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void -Obtains the OAuth token of an app account based on the specified authentication type. This API uses an asynchronous callback to return the result. +Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1062,23 +1484,39 @@ Obtains the OAuth token of an app account based on the specified authentication | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| | authType | string | Yes | Authentication type. | -| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. | +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name, owner or authType. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", (err, data) => { - console.log('getOAuthToken err: ' + JSON.stringify(err)); - console.log('getOAuthToken token: ' + data); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, token) => { + if (err) { + console.log("getAuthToken failed, error: " + JSON.stringify(err)); + } else { + console.log("getAuthToken successfully, token: " + token); + } + }); + } catch (err) { + console.log("getAuthToken exception: " + JSON.stringify(err)); + } ``` -### getOAuthToken8+ +### getAuthToken9+ -getOAuthToken(name: string, owner: string, authType: string): Promise<string> +getAuthToken(name: string, owner: string, authType: string): Promise<string> -Obtains the OAuth token of an app account based on the specified authentication type. This API uses a promise to return the result. +Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1090,28 +1528,41 @@ Obtains the OAuth token of an app account based on the specified authentication | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| | authType | string | Yes | Authentication type. | -**Parameters** +**Return value** -| Type | Description | +| Type | Description | | --------------------- | --------------------- | -| Promise<string> | Promise used to return the result.| +| Promise<string> | Promise used to return the authorization token obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or authType. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData").then((data) => { - console.log('getOAuthToken token: ' + data); - }).catch((err) => { - console.log("getOAuthToken err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((token) => { + console.log("getAuthToken successfully, token: " + token); + }).catch((err) => { + console.log("getAuthToken failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getAuthToken exception: " + JSON.stringify(err)); + } ``` -### setOAuthToken8+ +### setAuthToken9+ -setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void +setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void -Sets an OAuth token for an app account. This API uses an asynchronous callback to return the result. +Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1121,23 +1572,40 @@ Sets an OAuth token for an app account. This API uses an asynchronous callback t | -------- | ------------------------- | ---- | -------- | | name | string | Yes | Name of the target app account.| | authType | string | Yes | Authentication type. | -| token | string | Yes | OAuth token to set.| -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| +| token | string | Yes | Token to set.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or token. | +| 12300003 | Account not found. | +| 12400004 | The number of token reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => { - console.log('setOAuthToken err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx", (err) => { + if (err) { + console.log("setAuthToken failed, error: " + JSON.stringify(err)); + } else { + console.log("setAuthToken successfully"); + } + }); + } catch (err) { + console.log('setAuthToken exception: ' + JSON.stringify(err)); + } ``` -### setOAuthToken8+ +### setAuthToken9+ -setOAuthToken(name: string, authType: string, token: string): Promise<void> +setAuthToken(name: string, authType: string, token: string): Promise<void> -Sets an OAuth token for an app account. This API uses a promise to return the result. +Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1147,30 +1615,43 @@ Sets an OAuth token for an app account. This API uses a promise to return the re | -------- | ------ | ---- | -------- | | name | string | Yes | Name of the target app account.| | authType | string | Yes | Authentication type. | -| token | string | Yes | OAuth token to set.| +| token | string | Yes | Token to set.| -**Parameters** +**Return value** | Type | Description | | ------------------- | --------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or token. | +| 12300003 | Account not found. | +| 12400004 | The number of token reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => { - console.log('setOAuthToken successfully'); - }).catch((err) => { - console.log('setOAuthToken err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx").then(() => { + console.log("setAuthToken successfully"); + }).catch((err) => { + console.log("setAuthToken failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setAuthToken exception: " + JSON.stringify(err)); + } ``` -### deleteOAuthToken8+ +### deleteAuthToken9+ -deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void +deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void -Deletes the specified OAuth token for an app account. This API uses an asynchronous callback to return the result. +Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1181,23 +1662,40 @@ Deletes the specified OAuth token for an app account. This API uses an asynchron | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | | authType | string | Yes | Authentication type. | -| token | string | Yes | OAuth token to delete.| -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +| token | string | Yes | Token to delete.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or authType or token. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx", (err) => { - console.log('deleteOAuthToken err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => { + if (err) { + console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); + } else { + console.log("deleteAuthToken successfully"); + } + }); + } catch (err) { + console.log('deleteAuthToken exception: ' + JSON.stringify(err)); + } ``` -### deleteOAuthToken8+ +### deleteAuthToken9+ -deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> +deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> -Deletes the specified OAuth token for an app account. This API uses a promise to return the result. +Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1208,30 +1706,43 @@ Deletes the specified OAuth token for an app account. This API uses a promise to | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | | authType | string | Yes | Authentication type. | -| token | string | Yes | OAuth token to delete.| +| token | string | Yes | Token to delete.| -**Parameters** +**Return value** | Type | Description | | ------------------- | --------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or authType or token. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx").then(() => { - console.log('deleteOAuthToken successfully'); - }).catch((err) => { - console.log("deleteOAuthToken err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => { + console.log("deleteAuthToken successfully"); + }).catch((err) => { + console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); + }); + } catch (err) { + console.log('deleteAuthToken exception: ' + JSON.stringify(err)); + } ``` -### setOAuthTokenVisibility8+ +### setAuthTokenVisibility9+ -setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void +setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void -Sets the visibility of an OAuth token to an app. This API uses an asynchronous callback to return the result. +Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1242,57 +1753,91 @@ Sets the visibility of an OAuth token to an app. This API uses an asynchronous c | name | string | Yes | Name of the target app account. | | authType | string | Yes | Authentication type. | | bundleName | string | Yes | Bundle name of the app. | -| isVisible | boolean | Yes | Whether the OAuth token is visible to the app. The value **true** means visible, and the value **false** means the opposite.| -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or bundleName. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | +| 12400001 | Application not found. | +| 12400005 | The size of authorization list reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true, (err) => { - console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => { + if (err) { + console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err)); + } else { + console.log("setAuthTokenVisibility successfully"); + } + }); + } catch (err) { + console.log("setAuthTokenVisibility exception: " + JSON.stringify(err)); + } ``` -### setOAuthTokenVisibility8+ +### setAuthTokenVisibility9+ -setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> +setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> -Sets the visibility of an OAuth token to an app. This API uses a promise to return the result. +Sets the visibility of an authorization token to an app. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ------- | ---- | ------------ | -| name | string | Yes | Name of the target app account. | -| authType | string | Yes | Authentication type. | -| bundleName | string | Yes | Bundle name of the app.| -| isVisible | boolean | Yes | Whether the OAuth token is visible to the app. | +| Name | Type | Mandatory | Description | +| ---------- | ------------------------- | ---- | ------------------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| bundleName | string | Yes | Bundle name of the app. | +| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| -**Parameters** +**Return value** | Type | Description | | ------------------- | --------------------- | -| Promise<void> | Promise used to return the result.| +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or bundleName. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | +| 12400001 | Application not found. | +| 12400005 | The size of authorization list reaches the upper limit. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true).then(() => { - console.log('setOAuthTokenVisibility successfully'); - }).catch((err) => { - console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => { + console.log("setAuthTokenVisibility successfully"); + }).catch((err) => { + console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("setAuthTokenVisibility exception: " + JSON.stringify(err)); + } ``` -### checkOAuthTokenVisibility8+ +### checkAuthTokenVisibility9+ -checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void +checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void -Checks whether an OAuth token is visible to an app. This API uses an asynchronous callback to return the result. +Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1303,23 +1848,40 @@ Checks whether an OAuth token is visible to an app. This API uses an asynchronou | name | string | Yes | Name of the target app account. | | authType | string | Yes | Authentication type. | | bundleName | string | Yes | Bundle name of the app.| -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or bundleName. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", (err, data) => { - console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); - console.log('checkOAuthTokenVisibility isVisible: ' + data); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, isVisible) => { + if (err) { + console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err)); + } else { + console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible); + } + }); + } catch (err) { + console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err)); + } ``` -### checkOAuthTokenVisibility8+ +### checkAuthTokenVisibility9+ -checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> +checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> -Checks whether an OAuth token is visible to an app. This API uses a promise to return the result. +Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1331,28 +1893,42 @@ Checks whether an OAuth token is visible to an app. This API uses a promise to r | authType | string | Yes | Authentication type. | | bundleName | string | Yes | Bundle name of the app.| -**Parameters** +**Return value** | Type | Description | | ---------------------- | --------------------- | -| Promise<boolean> | Promise used to return the result.| +| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType or bundleName. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | +| 12400001 | Application not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo").then((data) => { - console.log('checkOAuthTokenVisibility isVisible: ' + data); - }).catch((err) => { - console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((isVisible) => { + console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible); + }).catch((err) => { + console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err)); + } ``` -### getAllOAuthTokens8+ +### getAllAuthTokens9+ -getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void +getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void -Obtains all OAuth tokens visible to the caller for an app account. This API uses an asynchronous callback to return the result. +Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1362,23 +1938,38 @@ Obtains all OAuth tokens visible to the caller for an app account. This API uses | -------- | ---------------------------------------- | ---- | ----------- | | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -| callback | AsyncCallback<Array< [OAuthTokenInfo](#oauthtokeninfo8)>> | Yes | Callback invoked to return the result. | +| callback | AsyncCallback<Array<[AuthTokenInfo](#authtokeninfo9)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner. | +| 12300003 | Account not found. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => { - console.log("getAllOAuthTokens err: " + JSON.stringify(err)); - console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo", (err, tokenArr) => { + if (err) { + console.log("getAllAuthTokens failed, error: " + JSON.stringify(err)); + } else { + console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr); + } + }); + } catch (err) { + console.log("getAllAuthTokens exception: " + JSON.stringify(err)); + } ``` -### getAllOAuthTokens8+ +### getAllAuthTokens9+ -getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> +getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>> -Obtains all OAuth tokens visible to the caller for an app account. This API uses a promise to return the result. +Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -1389,584 +1980,2519 @@ Obtains all OAuth tokens visible to the caller for an app account. This API uses | name | string | Yes | Name of the target app account. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -**Parameters** +**Return value** | Type | Description | | ---------------------------------------- | --------------------- | -| Promise<Array< [OAuthTokenInfo](#oauthtokeninfo8)>> | Promise used to return the result.| +| Promise<Array<[AuthTokenInfo](#authtokeninfo9)>> | Promise used to return the tokens obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner. | +| 12300003 | Account not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo").then((tokenArr) => { + console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr)); + }).catch((err) => { + console.log("getAllAuthTokens failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getAllAuthTokens exception: " + JSON.stringify(err)); + } + ``` + +### getAuthList9+ + +getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void + +Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type.| +| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData", (err, authList) => { + if (err) { + console.log("getAuthList failed, error: " + JSON.stringify(err)); + } else { + console.log("getAuthList successfully, authList: " + authList); + } + }); + } catch (err) { + console.log('getAuthList exception: ' + JSON.stringify(err)); + } + ``` + +### getAuthList9+ + +getAuthList(name: string, authType: string): Promise<Array<string>> + +Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | ------------------------------ | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type.| + +**Return value** + +| Type | Description | +| ---------------------------------- | --------------------- | +| Promise<Array<string>> | Promise used to return a list of authorized bundles.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or authType. | +| 12300003 | Account not found. | +| 12300107 | AuthType not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData").then((authList) => { + console.log("getAuthList successfully, authList: " + authList); + }).catch((err) => { + console.log("getAuthList failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getAuthList exception: " + JSON.stringify(err)); + } + ``` + +### getAuthCallback9+ + +getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void + +Obtains the authenticator callback for the authentication session. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------- | ---- | -------- | +| sessionId | string | Yes | ID of the authentication session.| +| callback | AsyncCallback<[AuthCallback](#authcallback9)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback object obtained. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid sessionId. | +| 12300108 | Session not found. | + +**Example** + + ```js + import featureAbility from '@ohos.ability.featureAbility'; + let appAccountManager = account_appAccount.createAppAccountManager(); + featureAbility.getWant((err, want) => { + var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; + try { + appAccountManager.getAuthCallback(sessionId, (err, callback) => { + if (err.code != account_appAccount.ResultCode.SUCCESS) { + console.log("getAuthCallback err: " + JSON.stringify(err)); + return; + } + var result = { + accountInfo: { + name: "Lisi", + owner: "com.example.accountjsdemo", + }, + tokenInfo: { + token: "xxxxxx", + authType: "getSocialData" + } + }; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + }); + } catch (err) { + console.log("getAuthCallback exception: " + JSON.stringify(err)); + } + }); + ``` + +### getAuthCallback9+ + +getAuthCallback(sessionId: string): Promise<AuthCallback> + +Obtains the authenticator callback for the authentication session. This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | -------- | +| sessionId | string | Yes | ID of the authentication session.| + +**Return value** + +| Type | Description | +| ------------------------------------ | --------------------- | +| Promise<[AuthCallback](#authcallback9)> | Promise used to return the authenticator callback obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid sessionId. | +| 12300108 | Session not found. | + +**Example** + + ```js + import featureAbility from '@ohos.ability.featureAbility'; + + let appAccountManager = account_appAccount.createAppAccountManager(); + featureAbility.getWant().then((want) => { + var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; + try { + appAccountManager.getAuthCallback(sessionId).then((callback) => { + var result = { + accountInfo: { + name: "Lisi", + owner: "com.example.accountjsdemo", + }, + tokenInfo: { + token: "xxxxxx", + authType: "getSocialData" + } + }; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + }).catch((err) => { + console.log("getAuthCallback err: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("getAuthCallback exception: " + JSON.stringify(err)); + } + }).catch((err) => { + console.log("getWant err: " + JSON.stringify(err)); + }); + ``` + +### queryAuthenticatorInfo9+ + +queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void + +Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | -------------------------------------- | ---- | ----------- | +| owner | string | Yes | Bundle name of the app.| +| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12300113 | Authenticator service not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo", (err, info) => { + if (err) { + console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err)); + } else { + console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); + } + }); + } catch (err) { + console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err)); + } + ``` + +### queryAuthenticatorInfo9+ + +queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> + +Obtains the authenticator information of an app. This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------- | +| owner | string | Yes | Bundle name of the app.| + +**Return value** + +| Type | Description | +| -------------------------------- | --------------------- | +| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12300113 | Authenticator service not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo").then((info) => { + console.log("queryAuthenticatorInfo successfully, info: " + JSON.stringify(info)); + }).catch((err) => { + console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err)); + } + ``` + +### checkAccountLabels9+ + +checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void; + +Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target app. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------------------------- | ----- | --------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| labels | Array<string> | Yes | Labels to check. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** or **false**. The value **true** means the app account has the labels; the value **false** means the opposite. If the operation fails, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or labels. | +| 12300003 | Account not found. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let labels = ["student"]; + try { + appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels, (err, hasAllLabels) => { + if (err) { + console.log("checkAccountLabels failed, error: " + JSON.stringify(err)); + } else { + console.log("checkAccountLabels successfully, hasAllLabels: " + hasAllLabels); + } + }); + } catch (err) { + console.log("checkAccountLabels exception: " + JSON.stringify(err)); + } + ``` + +### checkAccountLabels9+ + +checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean> + +Checks whether an app account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target app. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------------------------- | ----- | --------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| labels | Array<string> | Yes | Labels to check. | + +**Return value** + +| Type | Description | +| ------------------- | -------------------------------- | +| Promise<boolean> | Promise used to return the result. The value **true** means the app account has the labels; the value **false** means the opposite.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or labels. | +| 12300003 | Account not found. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let labels = ["student"]; + try { + appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels).then((hasAllLabels) => { + console.log('checkAccountLabels successfully: ' + hasAllLabels); + }).catch((err) => { + console.log("checkAccountLabels failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("checkAccountLabels exception: " + JSON.stringify(err)); + } + ``` + +### deleteCredential9+ + +deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void + +Deletes the credential of the specified type from an app account. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------------------------- | ----- | -------------- | +| name | string | Yes | Name of the target app account.| +| credentialType | string | Yes | Type of the credential to delete. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType. | +| 12300003 | Account not found. | +| 12300102 | Credential not found. | **Example** - ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => { - console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); - }).catch((err) => { - console.log("getAllOAuthTokens err: " + JSON.stringify(err)); + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.deleteCredential("zhangsan", "PIN_SIX", (err) => { + if (err) { + console.log("deleteCredential failed, error: " + JSON.stringify(err)); + } else { + console.log("deleteCredential successfully"); + } + }); + } catch (err) { + console.log("deleteCredential exception: " + JSON.stringify(err)); + } + ``` + +### deleteCredential9+ + +deleteCredential(name: string, credentialType: string): Promise<void> + +Deletes the credential of the specified type from an app account. This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------ | ----- | --------------- | +| name | string | Yes | Name of the target app account.| +| credentialType | string | Yes | Type of the credential to delete. | + +**Return value** + +| Type | Description | +| ------------------- | -------------------------------- | +| Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid name or credentialType. | +| 12300003 | Account not found. | +| 12300102 | Credential not found. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.deleteCredential("zhangsan", "PIN_SIX").then(() => { + console.log("deleteCredential successfully"); + }).catch((err) => { + console.log("deleteCredential failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("deleteCredential exception: " + JSON.stringify(err)); + } + ``` + +### selectAccountsByOptions9+ + +selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void + +Selects the accounts that can be accessed by the invoker based on the options. This API uses an asynchronous callback to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ----------------------------------- | ----- | --------------- | +| options | SelectAccountsOptions | Yes | Options for selecting accounts. | +| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accounts selected. Otherwise, **err** is an error object. | + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid options. | +| 12300010 | Account service busy. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + allowedOwners: [ "com.example.accountjsdemo" ], + requiredLabels: [ "student" ] + }; + try { + appAccountManager.selectAccountsByOptions(options, (err, accountArr) => { + if (err) { + console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err)); + } else { + console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr)); + } + }); + } catch (err) { + console.log("selectAccountsByOptions exception: " + JSON.stringify(err)); + } + ``` + +### selectAccountsByOptions9+ + +selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> + +Selects the accounts that can be accessed by the invoker based on the options. This API uses a promise to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------------------------- | ----- | --------------- | +| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | + +**Return value** + +| Type | Description | +| ------------------- | -------------------------------- | +| Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the accounts selected.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid options. | +| 12300010 | Account service busy. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + allowedOwners: ["com.example.accountjsdemo"] + }; + try { + appAccountManager.selectAccountsByOptions(options).then((accountArr) => { + console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr)); + }).catch((err) => { + console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err)); + }); + } catch (err) { + console.log("selectAccountsByOptions exception: " + JSON.stringify(err)); + } + ``` + +### verifyCredential9+ + +verifyCredential(name: string, owner: string, callback: AuthCallback): void; + +Verifies the credential of an app account. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ----- | ----------------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner. | +| 12300003 | Account not found. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", { + onResult: (resultCode, result) => { + console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("verifyCredential onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + } catch (err) { + console.log("verifyCredential err: " + JSON.stringify(err)); + } + ``` + +### verifyCredential9+ + +verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void; + +Verifies the user credential. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ----------------------- | ----- | ----------------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for verifying the user credential. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| + +**Error codes** + +| ID| Error Message| +| ------- | -------| +| 12300001 | System service exception. | +| 12300002 | Invalid name or owner or options. | +| 12300003 | Account not found. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + credentialType: "pin", + credential: "123456" + }; + try { + appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", options, { + onResult: (resultCode, result) => { + console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("verifyCredential onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + } catch (err) { + console.log("verifyCredential err: " + JSON.stringify(err)); + } + ``` + +### setAuthenticatorProperties9+ + +setAuthenticatorProperties(owner: string, callback: AuthCallback): void; + +Sets the authenticator attributes of an app. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ----- | ----------------------- | +| owner | string | Yes | Owner of the authenticator. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid owner. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + try { + appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", { + onResult: (resultCode, result) => { + console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + } catch (err) { + console.log("setAuthenticatorProperties err: " + JSON.stringify(err)); + } + ``` + +### setAuthenticatorProperties9+ + +setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void; + +Set authenticator properties. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ----- | ----------------------- | +| owner | string | Yes | Owner of the authenticator. | +| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| + +**Error codes** + +| ID| Error Message| +| ------- | ------- | +| 12300001 | System service exception. | +| 12300002 | Invalid owner or options. | +| 12300010 | Account service busy. | +| 12300113 | Authenticator service not found. | +| 12300114 | Authenticator service exception. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + let options = { + properties: {"prop1": "value1"} + }; + try { + appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", options, { + onResult: (resultCode, result) => { + console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + } catch (err) { + console.log("setAuthenticatorProperties err: " + JSON.stringify(err)); + } + + ``` + +### addAccount(deprecated) + +addAccount(name: string, callback: AsyncCallback<void>): void + +Adds an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +>This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9). + + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | -------------------- | +| name | string | Yes | Name of the target app account. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("WangWu", (err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + +### addAccount(deprecated) + +addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void + +Adds an app account name and additional information. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| name | string | Yes | Name of the target app account. | +| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("LiSi", "token101", (err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + +### addAccount(deprecated) + +addAccount(name: string, extraInfo?: string): Promise<void> + +Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | ---------------------------------------- | +| name | string | Yes | Name of the target app account. | +| extraInfo | string | No | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| + +**Return value** + +| Type | Description | +| ------------------- | --------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccount("LiSi", "token101").then(()=> { + console.log('addAccount Success'); + }).catch((err) => { + console.log("addAccount err: " + JSON.stringify(err)); + }); + ``` + +### addAccountImplicitly(deprecated) + +addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void + +Adds an app account implicitly based on the specified owner. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ---- | ----------------------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| authType | string | Yes | Authentication type. The authentication type is customized. | +| options | {[key: string]: any} | Yes | Authentication options, which can be set as required.| +| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the result. | + +**Example** + + ```js + import featureAbility from '@ohos.ability.featureAbility'; + + function onResultCallback(code, result) { + console.log("resultCode: " + code); + console.log("result: " + JSON.stringify(result)); + } + + function onRequestRedirectedCallback(request) { + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err)=>{ + console.log("startAbility err: " + JSON.stringify(err)); + }); + } + + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, { + onResult: onResultCallback, + onRequestRedirected: onRequestRedirectedCallback + }); + ``` + +### deleteAccount(deprecated) + +deleteAccount(name: string, callback: AsyncCallback<void>): void + +Deletes an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ---------------- | +| name | string | Yes | Name of the target app account. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccount("ZhaoLiu", (err) => { + console.log("deleteAccount err: " + JSON.stringify(err)); + }); + ``` + +### deleteAccount(deprecated) + +deleteAccount(name: string): Promise<void> + +Deletes an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------- | +| name | string | Yes | Name of the target app account.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccount("ZhaoLiu").then(() => { + console.log('deleteAccount Success'); + }).catch((err) => { + console.log("deleteAccount err: " + JSON.stringify(err)); + }); + ``` +### disableAppAccess(deprecated) + +disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void + +Disables an app account from accessing an app. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------------------------- | ---- | --------------------------------- | +| name | string | Yes | Name of the target app account. | +| bundleName | string | Yes | Bundle name of the app. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { + console.log("disableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### disableAppAccess(deprecated) + +disableAppAccess(name: string, bundleName: string): Promise<void> + +Disables an app account from accessing an app. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------ | ---- | ---------------- | +| name | string | Yes | Name of the target app account.| +| bundleName | string | Yes | Bundle name of the app. | + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { + console.log('disableAppAccess Success'); + }).catch((err) => { + console.log("disableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### enableAppAccess(deprecated) + +enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void + +Enables an app account to access an app. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------------------------- | ---- | --------------------------------- | +| name | string | Yes | Name of the target app account. | +| bundleName | string | Yes | Bundle name of the app. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { + console.log("enableAppAccess: " + JSON.stringify(err)); + }); + ``` + +### enableAppAccess(deprecated) + +enableAppAccess(name: string, bundleName: string): Promise<void> + +Enables an app account to access an app. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| bundleName | string | Yes | Bundle name of the app.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { + console.log('enableAppAccess Success'); + }).catch((err) => { + console.log("enableAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### checkAppAccountSyncEnable(deprecated) + +checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void + +Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9). + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------- | ---- | --------------------- | +| name | string | Yes | Name of the target app account. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { + console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); + console.log('checkAppAccountSyncEnable result: ' + result); + }); + ``` + +### checkAppAccountSyncEnable(deprecated) + +checkAppAccountSyncEnable(name: string): Promise<boolean> + +Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9-1). + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------- | +| name | string | Yes | Name of the target app account.| + +**Return value** + +| Type | Description | +| ---------------------- | --------------------- | +| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { + console.log('checkAppAccountSyncEnable, result: ' + data); + }).catch((err) => { + console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAccountCredential(deprecated) + +setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void + +Set credentials for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------------------------- | ---- | ------------- | +| name | string | Yes | Name of the target app account. | +| credentialType | string | Yes | Type of the credential to delete. | +| credential | string | Yes | Credential value. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { + console.log("setAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### setAccountCredential(deprecated) + +setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> + +Set credentials for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------ | ---- | ---------- | +| name | string | Yes | Name of the target app account. | +| credentialType | string | Yes | Type of the credential to delete.| +| credential | string | Yes | Credential value.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { + console.log('setAccountCredential Success'); + }).catch((err) => { + console.log("setAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### setAccountExtraInfo(deprecated) + +setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void + +Sets additional information for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9). + + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | --------------- | +| name | string | Yes | Name of the target app account. | +| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { + console.log("setAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### setAccountExtraInfo(deprecated) + +setAccountExtraInfo(name: string, extraInfo: string): Promise<void> + +Sets additional information for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1). + + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { + console.log('setAccountExtraInfo Success'); + }).catch((err) => { + console.log("setAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### setAppAccountSyncEnable(deprecated) + +setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void + +Sets data synchronization for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9). + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------- | +| name | string | Yes | Name of the target app account. | +| isEnable | boolean | Yes | Whether to enable data synchronization. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { + console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAppAccountSyncEnable(deprecated) + +setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> + +Sets data synchronization for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9-1). + +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------- | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| isEnable | boolean | Yes | Whether to enable data synchronization.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { + console.log('setAppAccountSyncEnable Success'); + }).catch((err) => { + console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); + }); + ``` + +### setAssociatedData(deprecated) + +setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void + +Sets data to be associated with an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9). + + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ----------------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the data to set.| +| value | string | Yes | Value of the data to set. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => { + console.log("setAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### setAssociatedData(deprecated) + +setAssociatedData(name: string, key: string, value: string): Promise<void> + +Sets data to be associated with an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1). + + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the data to set.| +| value | string | Yes | Value of the data to set.| + +**Return value** + +| Type | Description | +| :------------------ | :-------------------- | +| Promise<void> | Promise that returns no value.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { + console.log('setAssociatedData Success'); + }).catch((err) => { + console.log("setAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### getAllAccessibleAccounts(deprecated) + +getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void + +Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9). + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | --------- | +| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllAccessibleAccounts((err, data)=>{ + console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err)); + console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data)); + }); + ``` + +### getAllAccessibleAccounts(deprecated) + +getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> + +Obtains information about all accessible app accounts. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9-1). + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS + +**System capability**: SystemCapability.Account.AppAccount + +**Return value** + +| Type | Description | +| ---------------------------------------- | --------------------- | +| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the accessible app accounts.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllAccessibleAccounts().then((data) => { + console.log('getAllAccessibleAccounts: ' + data); + }).catch((err) => { + console.log("getAllAccessibleAccounts err: " + JSON.stringify(err)); + }); + ``` + +### getAllAccounts(deprecated) + +getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void + +Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9). + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | --------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return information about all accessible app accounts.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + const selfBundle = "com.example.actsgetallaaccounts"; + appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ + console.debug("getAllAccounts err:" + JSON.stringify(err)); + console.debug("getAllAccounts data:" + JSON.stringify(data)); + }); + ``` + +### getAllAccounts(deprecated) + +getAllAccounts(owner: string): Promise<Array<AppAccountInfo>> + +Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9-1). + +**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ------ | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| + +**Return value** + +| Type | Description | +| ---------------------------------------- | --------------------- | +| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise use to return the app accounts that can be accessed by the invoker.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + const selfBundle = "com.example.actsgetallaaccounts"; + appAccountManager.getAllAccounts(selfBundle).then((data) => { + console.log('getAllAccounts: ' + data); + }).catch((err) => { + console.log("getAllAccounts err: " + JSON.stringify(err)); + }); + ``` + +### getAccountCredential(deprecated) + +getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void + +Obtains the credential of an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | --------------------------- | ---- | -------------- | +| name | string | Yes | Name of the target app account. | +| credentialType | string | Yes | Type of the credential to delete.| +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { + console.log("getAccountCredential err: " + JSON.stringify(err)); + console.log('getAccountCredential result: ' + result); + }); + ``` + +### getAccountCredential(deprecated) + +getAccountCredential(name: string, credentialType: string): Promise<string> + +Obtains the credential of an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------------- | ------ | ---- | ---------- | +| name | string | Yes | Name of the target app account. | +| credentialType | string | Yes | Type of the credential to delete.| + +**Return value** + +| Type | Description | +| :-------------------- | :-------------------- | +| Promise<string> | Promise used to return the credential obtained.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { + console.log('getAccountCredential, result: ' + data); + }).catch((err) => { + console.log("getAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### getAccountExtraInfo(deprecated) + +getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void + +Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| name | string | Yes | Name of the target app account. | +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the additional information obtained. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { + console.log("getAccountExtraInfo err: " + JSON.stringify(err)); + console.log('getAccountExtraInfo result: ' + result); + }); + ``` + +### getAccountExtraInfo(deprecated) + +getAccountExtraInfo(name: string): Promise<string> + +Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------- | +| name | string | Yes | Name of the target app account.| + +**Return value** + +| Type | Description | +| :-------------------- | :-------------------- | +| Promise<string> | Promise used to return the additional information obtained.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { + console.log('getAccountExtraInfo, result: ' + data); + }).catch((err) => { + console.log("getAccountExtraInfo err: " + JSON.stringify(err)); + }); + ``` + +### getAssociatedData(deprecated) + +getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void + +Obtains data associated with an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ----------------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the data to obtain. | +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the data obtained. Otherwise, **err** is an error object.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { + console.log("getAssociatedData err: " + JSON.stringify(err)); + console.log('getAssociatedData result: ' + result); + }); + ``` + +### getAssociatedData(deprecated) + +getAssociatedData(name: string, key: string): Promise<string> + +Obtains data associated with an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | --------- | +| name | string | Yes | Name of the target app account. | +| key | string | Yes | Key of the data to obtain.| + +**Return value** + +| Type | Description | +| :-------------------- | :-------------------- | +| Promise<string> | Promise used to return the data obtained.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { + console.log('getAssociatedData: ' + data); + }).catch((err) => { + console.log("getAssociatedData err: " + JSON.stringify(err)); + }); + ``` + +### on('change')(deprecated) + +on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void + +Subscribes to account information changes of apps. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('accountChange')](#onaccountchange9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ------------------------------ | +| type | 'change' | Yes | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes.| +| owners | Array<string> | Yes | App bundle names of the account. | +| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the account changes. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + function changeOnCallback(data){ + console.debug("receive change data:" + JSON.stringify(data)); + } + try{ + appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); + } + catch(err){ + console.error("on accountOnOffDemo err:" + JSON.stringify(err)); + } + ``` + +### off('change')(deprecated) + +off(type: 'change', callback?: Callback>): void + +Unsubscribes from account information changes. + +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('accountChange')](#offaccountchange9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | -------------------------------- | ---- | ------------ | +| type | 'change' | Yes | Event type to unsubscribe from. The value is **'change'**, which indicates the account change event. | +| callback | Callback> | No | Callback to unregister.| + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + function changeOnCallback(data){ + console.debug("receive change data:" + JSON.stringify(data)); + appAccountManager.off('change', function(){ + console.debug("off finish"); + }) + } + try{ + appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); + } + catch(err){ + console.error("on accountOnOffDemo err:" + JSON.stringify(err)); + } + ``` + +### authenticate(deprecated) + +authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void + +Authenticates an app account with customized options. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9). + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------- | ---- | --------------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| authType | string | Yes | Authentication type. | +| options | {[key: string]: any} | Yes | Options for the authentication. | +| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Callback invoked to return the result.| + +**Example** + + ```js + import featureAbility from '@ohos.ability.featureAbility'; + + function onResultCallback(code, result) { + console.log("resultCode: " + code); + console.log("result: " + JSON.stringify(result)); + } + + function onRequestRedirectedCallback(request) { + let abilityStartSetting = {want: request}; + featureAbility.startAbility(abilityStartSetting, (err)=>{ + console.log("startAbility err: " + JSON.stringify(err)); + }); + } + + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, { + onResult: onResultCallback, + onRequestRedirected: onRequestRedirectedCallback }); ``` -### getOAuthList8+ +### getOAuthToken(deprecated) -getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void +getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void -Obtains a list of authorized OAuth tokens of an app account. This API uses an asynchronous callback to return the result. +Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ----------------------- | -| name | string | Yes | Name of the target app account. | -| authType | string | Yes | Authorization type.| -| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. | +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| authType | string | Yes | Authentication type. | +| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData", (err, data) => { - console.log('getOAuthList err: ' + JSON.stringify(err)); - console.log('getOAuthList data: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, data) => { + console.log('getOAuthToken err: ' + JSON.stringify(err)); + console.log('getOAuthToken token: ' + data); }); ``` -### getOAuthList8+ +### getOAuthToken(deprecated) -getOAuthList(name: string, authType: string): Promise<Array<string>> +getOAuthToken(name: string, owner: string, authType: string): Promise<string> -Obtains a list of authorized OAuth tokens of an app account. This API uses a promise to return the result. +Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------ | ---- | ----------------------- | -| name | string | Yes | Name of the target app account. | -| authType | string | Yes | Authorization type.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| authType | string | Yes | Authentication type. | -**Parameters** +**Return value** -| Type | Description | -| ---------------------------------- | --------------------- | -| Promise<Array<string>> | Promise used to return the result.| +| Type | Description | +| --------------------- | --------------------- | +| Promise<string> | Promise used to return the result.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData").then((data) => { - console.log('getOAuthList data: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => { + console.log('getOAuthToken token: ' + data); }).catch((err) => { - console.log("getOAuthList err: " + JSON.stringify(err)); + console.log("getOAuthToken err: " + JSON.stringify(err)); }); ``` -### getAuthenticatorCallback8+ +### setOAuthToken(deprecated) -getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void +setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void -Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. +Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| --------- | ---------------------------------------- | ---- | -------- | -| sessionId | string | Yes | ID of the authentication session.| -| callback | AsyncCallback<[AuthenticatorCallback](#authenticatorcallback8)> | Yes | Callback invoked to return the result.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | -------- | +| name | string | Yes | Name of the target app account.| +| authType | string | Yes | Authentication type. | +| token | string | Yes | Token to set.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| **Example** ```js - import featureAbility from '@ohos.ability.featureAbility'; - const appAccountManager = account_appAccount.createAppAccountManager(); - featureAbility.getWant((err, want) => { - var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; - appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => { - if (err.code != account_appAccount.ResultCode.SUCCESS) { - console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); - return; - } - var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", - [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", - [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", - [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.onResult(account_appAccount.ResultCode.SUCCESS, result); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => { + console.log('setOAuthToken err: ' + JSON.stringify(err)); }); ``` -### getAuthenticatorCallback8+ +### setOAuthToken(deprecated) -getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> +setOAuthToken(name: string, authType: string, token: string): Promise<void> -Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. +Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| --------- | ------ | ---- | -------- | -| sessionId | string | Yes | ID of the authentication session.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | -------- | +| name | string | Yes | Name of the target app account.| +| authType | string | Yes | Authentication type. | +| token | string | Yes | Authorization token to set.| -**Parameters** +**Return value** -| Type | Description | -| ------------------------------------ | --------------------- | -| Promise<[AuthenticatorCallback](#authenticatorcallback8)> | Promise used to return the result.| +| Type | Description | +| ------------------- | --------------------- | +| Promise<void> | Promise that returns no value.| **Example** ```js - import featureAbility from '@ohos.ability.featureAbility'; - - const appAccountManager = account_appAccount.createAppAccountManager(); - featureAbility.getWant().then((want) => { - var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; - appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { - var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", - [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", - [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", - [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.onResult(account_appAccount.ResultCode.SUCCESS, result); - }).catch((err) => { - console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); - }); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => { + console.log('setOAuthToken successfully'); }).catch((err) => { - console.log("getWant err: " + JSON.stringify(err)); + console.log('setOAuthToken err: ' + JSON.stringify(err)); }); ``` -### getAuthenticatorInfo8+ +### deleteOAuthToken(deprecated) -getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void +deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void + +Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. -Obtains authenticator information of an app account. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | -------------------------------------- | ---- | ----------- | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------ | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| authType | string | Yes | Authentication type. | +| token | string | Yes | Authorization token to delete.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => { - console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); - console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => { + console.log('deleteOAuthToken err: ' + JSON.stringify(err)); }); ``` -### getAuthenticatorInfo8+ +### deleteOAuthToken(deprecated) -getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> +deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> + +Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. -Obtains authenticator information of an app account. This API uses a promise to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ------ | ---- | ----------- | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | ------------ | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | +| authType | string | Yes | Authentication type. | +| token | string | Yes | Authorization token to delete.| -**Parameters** +**Return value** -| Type | Description | -| -------------------------------- | --------------------- | -| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the result.| +| Type | Description | +| ------------------- | --------------------- | +| Promise<void> | Promise that returns no value.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => { - console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => { + console.log('deleteOAuthToken successfully'); }).catch((err) => { - console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); + console.log("deleteOAuthToken err: " + JSON.stringify(err)); }); ``` -### checkAppAccess9+ +### setOAuthTokenVisibility(deprecated) -checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void +setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void + +Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. -Checks whether an app account is authorized to access an app. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ---------------------------- | ----- | ---------------- | -| name | string | Yes | Name of the target app account. | -| bundleName | string | Yes | Bundle name of the app to access. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | +| Name | Type | Mandatory | Description | +| ---------- | ------------------------- | ---- | ------------------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| bundleName | string | Yes | Bundle name of the app. | +| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => { - console.log('checkAppAccess: ' + JSON.stringify(data)); - console.log("checkAppAccess err: " + JSON.stringify(err)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => { + console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` -### checkAppAccess9+ +### setOAuthTokenVisibility(deprecated) -checkAppAccess(name: string, bundleName: string): Promise<boolean> +setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> + +Sets the visibility of an authorization token to an app. This API uses a promise to return the result. -Checks whether an app account is authorized to access an app. This API uses a promise to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ------ | ----- | ---------------- | -| name | string | Yes | Name of the target app account. | -| bundleName | string | Yes | Bundle name of the app to access. | +| Name | Type | Mandatory | Description | +| ---------- | ------- | ---- | ------------ | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| bundleName | string | Yes | Bundle name of the app.| +| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | -**Parameters** +**Return value** -| Type | Description | -| ---------------------- | --------------------------------- | -| Promise<boolean> | Promise used to return the result.| +| Type | Description | +| ------------------- | --------------------- | +| Promise<void> | Promise that returns no value.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { - console.log('checkAppAccess: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => { + console.log('setOAuthTokenVisibility successfully'); }).catch((err) => { - console.log("checkAppAccess err: " + JSON.stringify(err)); + console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` -### deleteAccountCredential9+ +### checkOAuthTokenVisibility(deprecated) -deleteAccountCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void +checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void + +Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. -Deletes the credential of an app account. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------------------------- | ----- | -------------- | -| name | string | Yes | Name of the target app account.| -| credentialType | string | Yes | Type of the credential to delete. | -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| +| Name | Type | Mandatory | Description | +| ---------- | ---------------------------- | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| bundleName | string | Yes | Bundle name of the app.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccountCredential("zhangsan", "pin", (err, data) => { - console.log('deleteAccountCredential: ' + JSON.stringify(data)); - console.log("deleteAccountCredential err: " + JSON.stringify(err)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => { + console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); + console.log('checkOAuthTokenVisibility isVisible: ' + data); }); ``` -### deleteAccountCredential9+ +### checkOAuthTokenVisibility(deprecated) + +checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> -deleteAccountCredential(name: string, credentialType: string): Promise<void> +Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. -Deletes the credential of an app account. This API uses a promise to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------ | ----- | --------------- | -| name | string | Yes | Name of the target app account.| -| credentialType | string | Yes | Type of the credential to delete. | +| Name | Type | Mandatory | Description | +| ---------- | ------ | ---- | ------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| bundleName | string | Yes | Bundle name of the app.| -**Parameters** +**Return value** -| Type | Description | -| ------------------- | -------------------------------- | -| Promise<void> | Promise used to return the result.| +| Type | Description | +| ---------------------- | --------------------- | +| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.deleteAccountCredential("zhangsan", "pin").then((data) => { - console.log('deleteAccountCredential: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => { + console.log('checkOAuthTokenVisibility isVisible: ' + data); }).catch((err) => { - console.log("deleteAccountCredential err: " + JSON.stringify(err)); + console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` -### checkAccountLabels9+ +### getAllOAuthTokens(deprecated) -checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void; +getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void + +Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. -Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------------------------- | ----- | --------------- | -| name | string | Yes | Name of the target app account. | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -| labels | Array<string> | Yes | Labels to check. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| callback | AsyncCallback<Array<[OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var labels = ["student"]; - appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", labels, (err, data) => { - console.log('checkAccountLabels: ' + JSON.stringify(data)); - console.log("checkAccountLabels err: " + JSON.stringify(err)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo", (err, data) => { + console.log("getAllOAuthTokens err: " + JSON.stringify(err)); + console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); }); ``` -### checkAccountLabels9+ +### getAllOAuthTokens(deprecated) -checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean> +getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> -Checks whether an app account has specific labels. This API uses a promise to return the result. +Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------------------------- | ----- | --------------- | -| name | string | Yes | Name of the target app account. | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -| labels | Array<string> | Yes | Labels to check. | +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------- | +| name | string | Yes | Name of the target app account. | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -**Parameters** +**Return value** -| Type | Description | -| ------------------- | -------------------------------- | -| Promise<boolean> | Promise used to return the result.| +| Type | Description | +| ---------------------------------------- | --------------------- | +| Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Promise used to return the tokens obtained.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var labels = ["student"]; - appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", labels).then((data) => { - console.log('checkAccountLabels: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => { + console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("checkAccountLabels err: " + JSON.stringify(err)); + console.log("getAllOAuthTokens err: " + JSON.stringify(err)); }); ``` -### selectAccountsByOptions9+ +### getOAuthList(deprecated) + +getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void -selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>); +Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses an asynchronous callback to return the result. -Selects the accounts accessible to the requester based on the options. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ----------------------------------- | ----- | --------------- | -| options | SelectAccountsOptions | Yes | Options for selecting accounts. | -| callback | AsyncCallback<[AppAccountInfo](#appaccountinfo)> | Yes | Callback invoked to return the result. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ----------------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type.| +| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var options = { - allowedOwners: ["com.example.ohos.accountjsdemo"] - }; - appAccountManager.selectAccountsByOptions(options, (err, data) => { - console.log('selectAccountsByOptions: ' + JSON.stringify(data)); - console.log("selectAccountsByOptions err: " + JSON.stringify(err)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData", (err, data) => { + console.log('getOAuthList err: ' + JSON.stringify(err)); + console.log('getOAuthList data: ' + JSON.stringify(data)); }); ``` -### selectAccountsByOptions9+ +### getOAuthList(deprecated) -selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> +getOAuthList(name: string, authType: string): Promise<Array<string>> -Selects the accounts accessible to the requester based on the options. This API uses a promise to return the result. +Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ------------------------- | ----- | --------------- | -| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | +| Name | Type | Mandatory | Description | +| -------- | ------ | ---- | ----------------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type.| -**Parameters** +**Return value** -| Type | Description | -| ------------------- | -------------------------------- | -| Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the result.| +| Type | Description | +| ---------------------------------- | --------------------- | +| Promise<Array<string>> | Promise used to return a list of authorized bundles.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var options = { - allowedOwners: ["com.example.ohos.accountjsdemo"] - }; - appAccountManager.selectAccountsByOptions(options).then((data) => { - console.log('selectAccountsByOptions: ' + JSON.stringify(data)); + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => { + console.log('getOAuthList data: ' + JSON.stringify(data)); }).catch((err) => { - console.log("selectAccountsByOptions err: " + JSON.stringify(err)); + console.log("getOAuthList err: " + JSON.stringify(err)); }); ``` -### verifyCredential9+ +### getAuthenticatorCallback(deprecated) -verifyCredential(name: string, owner: string, callback: AuthenticatorCallback): void; +getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void -Verifies the user credential. This API uses an asynchronous callback to return the result. +Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------- | ----- | ----------------------- | -| name | string | Yes | Name of the target app account. | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| +| Name | Type | Mandatory | Description | +| --------- | ---------------------------------------- | ---- | -------- | +| sessionId | string | Yes | ID of the authentication session.| +| callback | AsyncCallback<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback obtained. Otherwise, **err** is an error object.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", { - onResult: (resultCode, result) => { - console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); - console.log("verifyCredential onResult, result:" + JSON.stringify(result)); - }, - onRequestRedirected: (request) => { - console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); - } + import featureAbility from '@ohos.ability.featureAbility'; + let appAccountManager = account_appAccount.createAppAccountManager(); + featureAbility.getWant((err, want) => { + var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; + appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => { + if (err.code != account_appAccount.ResultCode.SUCCESS) { + console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); + return; + } + var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", + [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", + [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", + [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + }); }); ``` -### verifyCredential9+ +### getAuthenticatorCallback(deprecated) -verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): void; +getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> -Verifies the user credential. This API uses an asynchronous callback to return the result. +Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ----------------------- | ----- | ----------------------- | -| name | string | Yes | Name of the target app account. | -| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | -| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for verifying the user credential. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| +| Name | Type | Mandatory | Description | +| --------- | ------ | ---- | -------- | +| sessionId | string | Yes | ID of the authentication session.| + +**Return value** + +| Type | Description | +| ------------------------------------ | --------------------- | +| Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Promise used to return the authenticator callback obtained.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var options = { - credentialType: "pin", - credential: "123456" - }; - appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", options, { - onResult: (resultCode, result) => { - console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); - console.log("verifyCredential onResult, result:" + JSON.stringify(result)); - }, - onRequestRedirected: (request) => { - console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); - } + import featureAbility from '@ohos.ability.featureAbility'; + + let appAccountManager = account_appAccount.createAppAccountManager(); + featureAbility.getWant().then((want) => { + var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; + appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { + var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", + [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", + [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", + [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + }).catch((err) => { + console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); + }); + }).catch((err) => { + console.log("getWant err: " + JSON.stringify(err)); }); ``` -### setAuthenticatorProperties9+ +### getAuthenticatorInfo(deprecated) + +getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void -setAuthenticatorProperties(owner: string, callback: AuthenticatorCallback): void; +Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. -Sets authenticator properties. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------- | ----- | ----------------------- | -| owner | string | Yes | Owner of the authenticator. | -| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| +| Name | Type | Mandatory | Description | +| -------- | -------------------------------------- | ---- | ----------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| +| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", { - onResult: (resultCode, result) => { - console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); - console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); - }, - onRequestRedirected: (request) => { - console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); - } + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo", (err, data) => { + console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); + console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); }); ``` -### setAuthenticatorProperties9+ +### getAuthenticatorInfo(deprecated) + +getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> -setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthenticatorCallback): void; +Obtains the authenticator information of an app. This API uses a promise to return the result. -Sets authenticator properties. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9-1). **System capability**: SystemCapability.Account.AppAccount **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------- | ----- | ----------------------- | -| owner | string | Yes | Owner of the authenticator. | -| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------- | +| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| + +**Return value** + +| Type | Description | +| -------------------------------- | --------------------- | +| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); - var options = { - properties: {"prop1": "value1"} - }; - appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", options, { - onResult: (resultCode, result) => { - console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); - console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); - }, - onRequestRedirected: (request) => { - console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); - } + let appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo").then((data) => { + console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); }); ``` @@ -1979,19 +4505,35 @@ Defines app account information. | Name | Type | Mandatory | Description | | ----- | ------ | ---- | ----------- | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| -| name | string | Yes | Name of the app account. | +| name | string | Yes | Name of the target app account. | + +## AuthTokenInfo9+ + +Defines authorization token information. + +**System capability**: SystemCapability.Account.AppAccount + +| Name | Type | Mandatory | Description | +| -------------------- | -------------- | ----- | ---------------- | +| authType9+ | string | Yes | Authentication type. | +| token9+ | string | Yes | Value of the authorization token. | +| account9+ | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| + +## OAuthTokenInfo(deprecated) -## OAuthTokenInfo8+ +Defines authorization token information. -Defines OAuth token information. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthTokenInfo](#authtokeninfo9). **System capability**: SystemCapability.Account.AppAccount | Name | Type | Mandatory | Description | | -------------------- | -------------- | ----- | ---------------- | | authType | string | Yes | Authentication type. | -| token | string | Yes | Value of the token. | -| account9+ | AppAccountInfo | No | Account information of the token.| +| token | string | Yes | Value of the authorization token. | +| account9+ | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| ## AuthenticatorInfo8+ @@ -2005,9 +4547,41 @@ Defines OAuth authenticator information. | iconId | number | Yes | ID of the authenticator icon. | | labelId | number | Yes | ID of the authenticator label. | +## AuthResult9+ + +Defines the authentication result. + +**System capability**: SystemCapability.Account.AppAccount + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---------- | +| account | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| +| tokenInfo | [AuthTokenInfo](#authtokeninfo9) | No | Token information. | + +## CreateAccountOptions9+ + +Defines the options for creating an app account. + +**System capability**: SystemCapability.Account.AppAccount + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---------- | +| customData | {[key: string]: string} | No | Custom data.| + +## CreateAccountImplicitlyOptions9+ + +Defines the options for implicitly creating an app account. + +**System capability**: SystemCapability.Account.AppAccount + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---------- | +| requiredLabels | Array<string> | No | Labels required.| +| authType | string | No | Authentication type.| +| parameters | {[key: string]: Object} | No | Customized parameters.| ## SelectAccountsOptions9+ -Represents the options for selecting accounts. +Defines the options for selecting accounts. **System capability**: SystemCapability.Account.AppAccount @@ -2027,7 +4601,7 @@ Represents the options for verifying the user credential. | -------------- | ---------------------- | ----- | -------------- | | credentialType | string | No | Type of the credential to verify. | | credential | string | No | Credential value. | -| parameters | {[key:string]: Object} | No | Customized parameters.| +| parameters | {[key: string]: Object} | No | Customized parameters.| ## SetPropertiesOptions9+ @@ -2038,8 +4612,8 @@ Represents the options for setting authenticator properties. | Name | Type | Mandatory | Description | | ---------- | ---------------------- | ----- | -------------- | -| properties | {[key:string]: Object} | No | Authenticator properties. | -| parameters | {[key:string]: Object} | No | Customized parameters.| +| properties | {[key: string]: Object} | No | Authenticator properties. | +| parameters | {[key: string]: Object} | No | Customized parameters.| ## Constants8+ @@ -2047,12 +4621,16 @@ Enumerates the constants. **System capability**: SystemCapability.Account.AppAccount -| Name | Default Value | Description | +| Name | Value | Description | | -------------------------------- | ---------------------- | ----------------------- | -| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation of adding an account implicitly. | -| ACTION_AUTHENTICATE | "authenticate" | Authentication operation. | -| KEY_NAME | "name" | App account name. | -| KEY_OWNER | "owner" | Owner of an app account.| +| ACTION_ADD_ACCOUNT_IMPLICITLY(deprecated) | "addAccountImplicitly" | Operation of adding an account implicitly. | +| ACTION_AUTHENTICATE(deprecated) | "authenticate" | Authentication operation. | +| ACTION_CREATE_ACCOUNT_IMPLICITLY9+ | "createAccountImplicitly" | Operation of creating an account implicitly. | +| ACTION_AUTH9+ | "auth" | Authentication operation. | +| ACTION_VERIFY_CREDENTIAL9+ | "verifyCredential" | Operation of verifying credentials. | +| ACTION_SET_AUTHENTICATOR_PROPERTIES9+ | "setAuthenticatorProperties" | Operation of setting authenticator properties. | +| KEY_NAME | "name" | Name of the app account. | +| KEY_OWNER | "owner" | Owner of the app account.| | KEY_TOKEN | "token" | Token. | | KEY_ACTION | "action" | Operation. | | KEY_AUTH_TYPE | "authType" | Authentication type. | @@ -2069,7 +4647,7 @@ Enumerates the result codes. **System capability**: SystemCapability.Account.AppAccount -| Name | Default Value | Description | +| Name | Value | Description | | ----------------------------------- | ----- | ------------ | | SUCCESS | 0 | The operation is successful. | | ERROR_ACCOUNT_NOT_EXIST | 10001 | The app account does not exist. | @@ -2085,16 +4663,122 @@ Enumerates the result codes. | ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | The OAuth service is abnormal. | | ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | The session to be authenticated does not exist. | | ERROR_OAUTH_TIMEOUT | 10013 | The authentication timed out. | -| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | The OAuth token does not exist.| +| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | The authorization token does not exist.| | ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | The number of OAuth tokens reaches the limit. | | ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | The authentication operation is not supported. | | ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | The authentication type is not supported. | | ERROR_PERMISSION_DENIED | 10018 | The required permission is missing. | -## AuthenticatorCallback8+ +## AuthCallback9+ + +Implements authenticator callbacks. + +### onResult9+ + +onResult: (code: number, result?: AuthResult) => void + +Called to return the result of an authentication request. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------ | -------------------- | ---- | ------ | +| code | number | Yes | Authentication result code.| +| result | [AuthResult](#authresult9) | No | Authentication result. | + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + var sessionId = "1234"; + appAccountManager.getAuthCallback(sessionId).then((callback) => { + var result = { + accountInfo: { + name: "Lisi", + owner: "com.example.accountjsdemo", + }, + tokenInfo: { + token: "xxxxxx", + authType: "getSocialData" + } + }; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + }).catch((err) => { + console.log("getAuthCallback err: " + JSON.stringify(err)); + }); + ``` + +### onRequestRedirected9+ + +onRequestRedirected: (request: Want) => void + +Called to redirect a request. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ---- | ---- | ---------- | +| request | Want | Yes | Request to be redirected.| + +**Example** + + ```js + class MyAuthenticator extends account_appAccount.Authenticator { + createAccountImplicitly(options, callback) { + callback.onRequestRedirected({ + bundleName: "com.example.accountjsdemo", + abilityName: "com.example.accountjsdemo.LoginAbility", + }); + } + + auth(name, authType, options, callback) { + var result = { + accountInfo: { + name: "Lisi", + owner: "com.example.accountjsdemo", + }, + tokenInfo: { + token: "xxxxxx", + authType: "getSocialData" + } + }; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } + } + ``` + +### onRequestContinued9+ + +onRequestContinued?: () => void + +Called to continue to process the request. + +**System capability**: SystemCapability.Account.AppAccount + +**Example** + + ```js + let appAccountManager = account_appAccount.createAppAccountManager(); + var sessionId = "1234"; + appAccountManager.getAuthCallback(sessionId).then((callback) => { + callback.onRequestContinued(); + }).catch((err) => { + console.log("getAuthCallback err: " + JSON.stringify(err)); + }); + ``` + +## AuthenticatorCallback(deprecated) Provides OAuth authenticator callbacks. +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthCallback](#authcallback9). + ### onResult8+ onResult: (code: number, result: {[key: string]: any}) => void @@ -2113,11 +4797,11 @@ Called to return the result of an authentication request. **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); + let appAccountManager = account_appAccount.createAppAccountManager(); var sessionId = "1234"; appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", - [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo", + [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; callback.onResult(account_appAccount.ResultCode.SUCCESS, result); @@ -2146,8 +4830,8 @@ Called to redirect a request. class MyAuthenticator extends account_appAccount.Authenticator { addAccountImplicitly(authType, callerBundleName, options, callback) { callback.onRequestRedirected({ - bundleName: "com.example.ohos.accountjsdemo", - abilityName: "com.example.ohos.accountjsdemo.LoginAbility", + bundleName: "com.example.accountjsdemo", + abilityName: "com.example.accountjsdemo.LoginAbility", }); } @@ -2171,7 +4855,7 @@ Called to continue to process the request. **Example** ```js - const appAccountManager = account_appAccount.createAppAccountManager(); + let appAccountManager = account_appAccount.createAppAccountManager(); var sessionId = "1234"; appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { callback.onRequestContinued(); @@ -2184,11 +4868,30 @@ Called to continue to process the request. Provides APIs to operate the authenticator. -### addAccountImplicitly8+ +### createAccountImplicitly9+ + +createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void + +Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------------- | --------------------- | ---- | --------------- | +| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| + +### addAccountImplicitlydeprecated addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void -Implicitly adds an app account based on the specified authentication type and options. This API uses an asynchronous callback to return the result. +Adds an app account implicitly based on the specified authentication type and options. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9-2). **System capability**: SystemCapability.Account.AppAccount @@ -2199,13 +4902,35 @@ Implicitly adds an app account based on the specified authentication type and op | authType | string | Yes | Authentication type. | | callerBundleName | string | Yes | Bundle name of the authentication requester. | | options | {[key: string]: any} | Yes | Options for the authentication. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the authentication result.| +| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the authentication result.| + +### auth9+ + +auth(name: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void + +Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.AppAccount + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---------------- | --------------------- | ---- | --------------- | +| name | string | Yes | Name of the target app account. | +| authType | string | Yes | Authentication type. | +| callerBundleName | string | Yes | Authentication type. | +| options | {[key: string]: Object} | Yes | Options for the authentication. | +| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| -### authenticate8+ +### authenticatedeprecated authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void -Authenticates an app account to obtain the OAuth token. This API uses an asynchronous callback to return the result. +Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. + +> **NOTE** +> +> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9-2). **System capability**: SystemCapability.Account.AppAccount @@ -2217,11 +4942,11 @@ Authenticates an app account to obtain the OAuth token. This API uses an asynchr | authType | string | Yes | Authentication type. | | callerBundleName | string | Yes | Bundle name of the authentication requester. | | options | {[key: string]: any} | Yes | Options for the authentication. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the authentication result.| +| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the authentication result.| ### verifyCredential9+ -verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): void; +verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void; Verifies the credential of an app account. This API uses an asynchronous callback to return the result. @@ -2233,13 +4958,13 @@ Verifies the credential of an app account. This API uses an asynchronous callbac | ---------------- | --------------------- | ---- | --------------- | | name | string | Yes | Name of the target app account. | | options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for credential verification. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the verification result.| ### setProperties9+ -setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback): void; +setProperties(options: SetPropertiesOptions, callback: AuthCallback): void; -Sets authenticator properties. This API uses an asynchronous callback to return the result. +Sets the authenticator properties. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount @@ -2248,11 +4973,11 @@ Sets authenticator properties. This API uses an asynchronous callback to return | Name | Type | Mandatory | Description | | ---------------- | --------------------- | ---- | --------------- | | options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| ### checkAccountLabels9+ -checkAccountLabels(name: string, labels: Array<string>, callback: AuthenticatorCallback): void; +checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void; Checks the account labels. This API uses an asynchronous callback to return the result. @@ -2264,11 +4989,11 @@ Checks the account labels. This API uses an asynchronous callback to return the | ---------------- | --------------------- | ---- | --------------- | | name | string | Yes | Name of the target app account. | | labels | Array<string> | Yes | Labels to check. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the check result.| +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the check result.| ### isAccountRemovable9+ -isAccountRemovable(name: string, callback: AuthenticatorCallback): void; +isAccountRemovable(name: string, callback: AuthCallback): void; Checks whether an app account can be deleted. This API uses an asynchronous callback to return the result. @@ -2279,7 +5004,7 @@ Checks whether an app account can be deleted. This API uses an asynchronous call | Name | Type | Mandatory | Description | | ---------------- | --------------------- | ---- | --------------- | | name | string | Yes | Name of the target app account. | -| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| +| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| ### getRemoteObject9+ @@ -2293,49 +5018,49 @@ Obtains the remote object of an authenticator. This API cannot be overloaded. ```js class MyAuthenticator extends account_appAccount.Authenticator { - addAccountImplicitly(authType, callerBundleName, options, callback) { - callback.onRequestRedirected({ - bundleName: "com.example.ohos.accountjsdemo", - abilityName: "com.example.ohos.accountjsdemo.LoginAbility", - }); - } + addAccountImplicitly(authType, callerBundleName, options, callback) { + callback.onRequestRedirected({ + bundleName: "com.example.accountjsdemo", + abilityName: "com.example.accountjsdemo.LoginAbility", + }); + } - authenticate(name, authType, callerBundleName, options, callback) { - var result = {[account_appAccount.Constants.KEY_NAME]: name, - [account_appAccount.Constants.KEY_AUTH_TYPE]: authType, - [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; - callback.onResult(account_appAccount.ResultCode.SUCCESS, result); - } + authenticate(name, authType, callerBundleName, options, callback) { + var result = {[account_appAccount.Constants.KEY_NAME]: name, + [account_appAccount.Constants.KEY_AUTH_TYPE]: authType, + [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } - verifyCredential(name, options, callback) { - callback.onRequestRedirected({ - bundleName: "com.example.ohos.accountjsdemo", - abilityName: "com.example.ohos.accountjsdemo.VerifyAbility", - parameters: { - name: name - } - }); - } + verifyCredential(name, options, callback) { + callback.onRequestRedirected({ + bundleName: "com.example.accountjsdemo", + abilityName: "com.example.accountjsdemo.VerifyAbility", + parameters: { + name: name + } + }); + } - setProperties(options, callback) { - callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); - } + setProperties(options, callback) { + callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); + } - checkAccountLabels(name, labels, callback) { - var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; - callback.onResult(account_appAccount.ResultCode.SUCCESS, result); - } - - isAccountRemovable(name, callback) { - var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true}; - callback.onResult(account_appAccount.ResultCode.SUCCESS, result); - } + checkAccountLabels(name, labels, callback) { + var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } + + isAccountRemovable(name, callback) { + var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } } var authenticator = null; export default { - onConnect(want) { - authenticator = new MyAuthenticator(); - return authenticator.getRemoteObject(); - } + onConnect(want) { + authenticator = new MyAuthenticator(); + return authenticator.getRemoteObject(); + } } ``` diff --git a/en/application-dev/reference/apis/js-apis-distributed-account.md b/en/application-dev/reference/apis/js-apis-distributed-account.md index 4dc76cd2d39f631d74d5c51b61259bd88a1ea924..505587d21e4cd4b792ff97282b10ae1bc4662359 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-account.md +++ b/en/application-dev/reference/apis/js-apis-distributed-account.md @@ -1,18 +1,17 @@ # Distributed Account Management -The distributedAccount module provides basic functions for managing distributed accounts, including querying and updating account login status. +The **distributedAccount** module provides APIs for managing distributed accounts, including querying and updating account login status. > **NOTE**
+> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. - ## Modules to Import ```js import account_distributedAccount from '@ohos.account.distributedAccount'; ``` - ## account_distributedAccount.getDistributedAccountAbility getDistributedAccountAbility(): DistributedAccountAbility @@ -25,7 +24,7 @@ Obtains a **DistributedAccountAbility** instance. | Type| Description| | -------- | -------- | - | [DistributedAccountAbility](#distributedaccountability) | **DistributedAccountAbility** instance obtained. This instance provides methods for querying and updating the login state of a distributed account.| + | [DistributedAccountAbility](#distributedaccountability) | **DistributedAccountAbility** instance obtained. This instance provides APIs for querying and updating the login state of a distributed account.| **Example** ```js @@ -34,13 +33,88 @@ Obtains a **DistributedAccountAbility** instance. ## DistributedAccountAbility -Provides methods for querying and updating the login state of a distributed account. You must obtain a **DistributedAccountAbility** instance first. +Provides APIs for querying and updating the login state of a distributed account. You must obtain a **DistributedAccountAbility** instance first. + +### getOsAccountDistributedInfo9+ + +getOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void + +Obtains distributed account information. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.OsAccount + +**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS, ohos.permission.GET_DISTRIBUTED_ACCOUNTS, or ohos.permission.DISTRIBUTED_DATASYNC + +**Parameters** + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and data is the distributed account information obtained. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| -------- | ------------------- | +| 12300001 | System service exception. | + +**Example** + ```js + const accountAbility = account_distributedAccount.getDistributedAccountAbility(); + try { + accountAbility.getOsAccountDistributedInfo((err, data) => { + console.log("getOsAccountDistributedInfo err: " + JSON.stringify(err)); + console.log('Query account info name: ' + data.name); + console.log('Query account info id: ' + data.id); + }); + } catch (e) { + console.log("getOsAccountDistributedInfo exception: " + JSON.stringify(e)); + } + ``` -### queryOsAccountDistributedInfo +### getOsAccountDistributedInfo9+ + +getOsAccountDistributedInfo(): Promise<DistributedInfo> + +Obtains distributed account information. This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.OsAccount + +**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS, ohos.permission.GET_DISTRIBUTED_ACCOUNTS, or ohos.permission.DISTRIBUTED_DATASYNC + +**Return value** + + | Type| Description| + | -------- | -------- | + | Promise<[DistributedInfo](#distributedinfo)> | Promise used to return the distributed account information obtained.| + +**Error codes** + +| ID| Error Message| +| -------- | ------------------- | +| 12300001 | System service exception. | + +**Example** + ```js + const accountAbility = account_distributedAccount.getDistributedAccountAbility(); + try { + accountAbility.getOsAccountDistributedInfo().then((data) => { + console.log('Query account info name: ' + data.name); + console.log('Query account info id: ' + data.id); + }).catch((err) => { + console.log("getOsAccountDistributedInfo err: " + JSON.stringify(err)); + }); + } catch (e) { + console.log("getOsAccountDistributedInfo exception: " + JSON.stringify(e)); + } + ``` +### queryOsAccountDistributedInfo(deprecated) queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void Obtains distributed account information. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountDistributedInfo](#getosaccountdistributedinfo9). **System capability**: SystemCapability.Account.OsAccount @@ -50,24 +124,28 @@ Obtains distributed account information. This API uses an asynchronous callback | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the distributed account information obtained.| + | callback | AsyncCallback<[DistributedInfo](#distributedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and data is the distributed account information obtained. Otherwise, **err** is an error object.| **Example** ```js const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - accountAbility.queryOsAccountDistributedInfo((err, data) => { + accountAbility.queryOsAccountDistributedInfo((err, data) => { console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err)); console.log('Query account info name: ' + data.name); console.log('Query account info id: ' + data.id); }); ``` -### queryOsAccountDistributedInfo +### queryOsAccountDistributedInfo(deprecated) queryOsAccountDistributedInfo(): Promise<DistributedInfo> Obtains distributed account information. This API uses a promise to return the result. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getOsAccountDistributedInfo](#getosaccountdistributedinfo9-1). + **System capability**: SystemCapability.Account.OsAccount **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.DISTRIBUTED_DATASYNC @@ -81,7 +159,7 @@ Obtains distributed account information. This API uses a promise to return the r **Example** ```js const accountAbility = account_distributedAccount.getDistributedAccountAbility(); - accountAbility.queryOsAccountDistributedInfo().then((data) => { + accountAbility.queryOsAccountDistributedInfo().then((data) => { console.log('Query account info name: ' + data.name); console.log('Query account info id: ' + data.id); }).catch((err) => { @@ -89,12 +167,97 @@ Obtains distributed account information. This API uses a promise to return the r }); ``` -### updateOsAccountDistributedInfo +### setOsAccountDistributedInfo9+ + +setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void + +Sets the distributed account information. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Account.OsAccount + +**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS + +**Parameters** + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.| + | callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the distributed account information is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.| + +**Error codes** + +| ID| Error Message| +| -------- | ------------------- | +| 12300001 | System service exception. | +| 12300002 | Invalid accountInfo. | +| 12300003 | Account not found. | + +**Example** + ```js + const accountAbility = account_distributedAccount.getDistributedAccountAbility(); + let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; + try { + accountAbility.setOsAccountDistributedInfo(accountInfo, (err) => { + console.log("setOsAccountDistributedInfo err: " + JSON.stringify(err)); + }); + } catch (e) { + console.log("setOsAccountDistributedInfo exception: " + JSON.stringify(e)); + } + ``` + +### setOsAccountDistributedInfo9+ + +setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void> + +Sets the distributed account information. This API uses a promise to return the result. + +**System capability**: SystemCapability.Account.OsAccount + +**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS + +**Parameters** + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.| + +**Return value** + + | Type| Description| + | -------- | -------- | + | Promise<void> | Promise that returns no value.| + +**Error codes** + +| ID| Error Message| +| -------- | ------------------- | +| 12300001 | System service exception. | +| 12300002 | invalid accountInfo. | + +**Example** + ```js + const accountAbility = account_distributedAccount.getDistributedAccountAbility(); + let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; + try { + accountAbility.setOsAccountDistributedInfo(accountInfo).then(() => { + console.log('setOsAccountDistributedInfo Success'); + }).catch((err) => { + console.log("setOsAccountDistributedInfo err: " + JSON.stringify(err)); + }); + } catch (e) { + console.log("setOsAccountDistributedInfo exception: " + JSON.stringify(e)); + } + ``` +### updateOsAccountDistributedInfo(deprecated) updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<void>): void Updates distributed account information. This API uses an asynchronous callback to return the result. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setOsAccountDistributedInfo](#setosaccountdistributedinfo9). + **System capability**: SystemCapability.Account.OsAccount **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS @@ -103,24 +266,26 @@ Updates distributed account information. This API uses an asynchronous callback | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | accountInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information.| - | callback | AsyncCallback<void> | Yes| Callback invoked when the distributed account information is updated.| + | accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.| + | callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the distributed account information is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.| **Example** ```js const accountAbility = account_distributedAccount.getDistributedAccountAbility(); let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'}; - accountAbility.updateOsAccountDistributedInfo(accountInfo, (err) => { + accountAbility.updateOsAccountDistributedInfo(accountInfo, (err) => { console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err)); }); ``` -### updateOsAccountDistributedInfo +### updateOsAccountDistributedInfo(deprecated) updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void> -Updates distributed account information. This API uses a promise to return the result. - +Updates the distributed account information. This API uses a promise to return the result. +> **NOTE** +> +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setOsAccountDistributedInfo](#setosaccountdistributedinfo9-1). **System capability**: SystemCapability.Account.OsAccount **Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS @@ -129,13 +294,13 @@ Updates distributed account information. This API uses a promise to return the r | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | accountInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information.| + | accountInfo | [DistributedInfo](#distributedinfo) | Yes| New distributed account information.| **Return value** | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the result.| + | Promise<void> | Promise that returns no value.| **Example** ```js @@ -147,8 +312,6 @@ Updates distributed account information. This API uses a promise to return the r console.log("updateOsAccountDistributedInfo err: " + JSON.stringify(err)); }); ``` - - ## DistributedInfo Defines distributed OS account information. @@ -157,7 +320,9 @@ Defines distributed OS account information. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| name | string | Yes| Name of a distributed account. It must be a non-null string.| -| id | string | Yes| UID of a distributed account. It must be a non-null string.| +| name | string | Yes| Name of the distributed account. It must be a non-null string.| +| id | string | Yes| UID of the distributed account. It must be a non-null string.| | event | string | Yes| Login state of a distributed account. The state can be login, logout, token invalid, or logoff, which correspond to the following strings respectively:
- Ohos.account.event.LOGIN
- Ohos.account.event.LOGOUT
- Ohos.account.event.TOKEN_INVALID
- Ohos.account.event.LOGOFF | -| scalableData | object | No| Extended information about a distributed account. Customized information is passed in key-value pairs.
Note: This parameter is reserved and not used in query and update methods.| +| nickname9+ | string | No| Nickname of the distributed account. It must be a non-null string.| +| avatar9+ | string | No| Avatar of the distributed account. It must be a non-null string.| +| scalableData | object | No| Extended information about the distributed account, passed in key-value (KV) pairs.
**NOTE**
This parameter is reserved and not used in query and update methods.| diff --git a/en/application-dev/reference/apis/js-apis-osAccount.md b/en/application-dev/reference/apis/js-apis-osAccount.md index 36e075f0e24f3a01dfc7feddc29173c364e0b885..068e2a1ca6c4c01c2e69144354bd90b86302619a 100644 --- a/en/application-dev/reference/apis/js-apis-osAccount.md +++ b/en/application-dev/reference/apis/js-apis-osAccount.md @@ -37,7 +37,7 @@ Enumerates the OS account types. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ------ | ------ | ----------- | | ADMIN | 0 | Administrator account| | NORMAL | 1 | Normal account | @@ -154,7 +154,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------ | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, multiple OS accounts are supported. If **false** is returned, multiple OS accounts are not supported.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| **Error codes** @@ -191,7 +191,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re | Type | Description | | :--------------------- | :--------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, multiple OS accounts are supported. If **false** is returned, multiple OS accounts are not supported.| +| Promise<boolean> | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| **Error codes** @@ -220,7 +220,7 @@ checkOsAccountActivated(localId: number, callback: AsyncCallback<boolean>) Checks whether an OS account is activated. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS +**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS **System capability**: SystemCapability.Account.OsAccount @@ -229,7 +229,7 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------ | | localId | number | Yes | ID of the target OS account. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account is activated. If **false** is returned, the account is not activated.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.| **Error codes** @@ -277,7 +277,7 @@ Checks whether an OS account is activated. This API uses a promise to return the | Type | Description | | ---------------------- | ---------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account is activated. If **false** is returned, the account is not activated.| +| Promise<boolean> | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.| **Error codes** @@ -309,7 +309,7 @@ checkConstraintEnabled(localId: number, constraint: string, callback: AsyncCallb Checks whether the specified constraint is enabled for an OS account. This API uses an asynchronous callback to return the result. -**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS +**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS **System capability**: SystemCapability.Account.OsAccount @@ -319,7 +319,7 @@ Checks whether the specified constraint is enabled for an OS account. This API u | ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | | localId | number | Yes | ID of the target OS account. | | constraint | string | Yes | [Constraint](#constraints) to check. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the constraint is enabled. If **false** is returned, the constraint is not enabled.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| **Error codes** @@ -369,7 +369,7 @@ Checks whether the specified constraint is enabled for an OS account. This API u | Type | Description | | --------------------- | --------------------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the constraint is enabled. If **false** is returned, the constraint is not enabled.| +| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| **Error codes** @@ -408,7 +408,7 @@ Checks whether this OS account is a test account. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account is a test account. If **false** is returned, the account is not a test account.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| **Error codes** @@ -445,7 +445,7 @@ Checks whether this OS account is a test account. This API uses a promise to ret | Type | Description | | ---------------------- | ------------------------------------------------------------------------ | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account is a test account. If **false** is returned, the account is not a test account.| +| Promise<boolean> | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| **Error codes** @@ -482,7 +482,7 @@ Checks whether this OS account has been verified. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If true is returned, the current account has been verified. If false is returned, the current account has not been verified.| **Error codes** @@ -523,8 +523,8 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- | -| localId | number | No | ID of the target OS account. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| localId | number | Yes | ID of the target OS account. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| **Error codes** @@ -572,7 +572,7 @@ Checks whether an OS account has been verified. This API uses a promise to retur | Type | Description | | ---------------------- | ----------------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| Promise<boolean> | Promise used to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| **Error codes** @@ -814,7 +814,7 @@ Sets a name for an OS account. This API uses an asynchronous callback to return | Name | Type | Mandatory| Description | | :-------- | ------------------------- | ---- | ----------------------------------------------- | | localId | number | Yes | ID of the target OS account. | -| localName | string | Yes | Account name to set. The value cannot exceed 1024 characters. | +| localName | string | Yes | Account name. The value cannot exceed 1024 characters. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| **Error codes** @@ -1918,7 +1918,7 @@ Obtains the type of the account to which the current process belongs. This API u getOsAccountType(): Promise<OsAccountType> -Obtains the type of the OS account to which the current process belongs. This API uses a promise to return the result. +Obtains the type of the account to which the current process belongs. This API uses a promise to return the result. **System capability**: SystemCapability.Account.OsAccount @@ -2130,7 +2130,7 @@ Sets a profile photo for an OS account. This API uses an asynchronous callback t | -------- | ------------------------- | ---- | ------------ | | localId | number | Yes | ID of the target OS account.| | photo | string | Yes | Profile photo information. | -| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | **Error codes** @@ -2381,7 +2381,7 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void -Subscribes to OS account changes. This API uses a callback to return the result. +Subscribes to the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -2393,9 +2393,9 @@ Subscribes to OS account changes. This API uses a callback to return the result. | Name | Type | Mandatory| Description | | -------- | -------------------------- | ---- | ------------------------------------------------------------ | -| type | 'activate' \| 'activating' | Yes | Type of the event to subscribe to. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated.| +| type | 'activate' \| 'activating' | Yes | Type of the event to subscribe to. The value **activate** indicates an event reported when the OS account activation is complete, and **activating** indicates an event reported when OS account is being activated.| | name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes. | -| callback | Callback<number> | Yes | Callback invoked to return the OS account ID and status changes. | +| callback | Callback<number> | Yes | Callback invoked to return the ID of the OS account being activated or activated. | **Error codes** @@ -2423,7 +2423,7 @@ Subscribes to OS account changes. This API uses a callback to return the result. off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void -Unsubscribes from OS account changes. This API uses a callback to return the result. +Unsubscribes from the OS account activation states, including the states of the account being activated and the account with activation completed. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -2437,7 +2437,7 @@ Unsubscribes from OS account changes. This API uses a callback to return the res | -------- | -------------------------- | ---- | ------------------------------------------------------------ | | type | 'activate' \| 'activating' | Yes | Type of the event to unsubscribe from. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated.| | name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.| -| callback | Callback<number> | No | Callback for OS account changes. By default, **0** is returned. | +| callback | Callback<number> | No | Callback to unregister. By default, **0** is returned. | **Error codes** @@ -2725,7 +2725,7 @@ Checks whether multiple OS accounts are supported. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------ | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, multiple OS accounts are supported. If **false** is returned, multiple OS accounts are not supported.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| **Example** @@ -2756,7 +2756,7 @@ Checks whether multiple OS accounts are supported. This API uses a promise to re | Type | Description | | :--------------------- | :--------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, multiple OS accounts are supported. If **false** is returned, multiple OS accounts are not supported.| +| Promise<boolean> | Promise used to return the result. The value **true** means multiple OS accounts are supported; the value false means the opposite.| **Example** @@ -2789,7 +2789,7 @@ Checks whether an OS account is activated. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------ | | localId | number | Yes | ID of the target OS account. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account is activated. If **false** is returned, the account is not activated.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is activated; the value **false** means the opposite.| **Example**: Check whether OS account 100 is activated. @@ -2829,7 +2829,7 @@ Checks whether an OS account is activated. This API uses a promise to return the | Type | Description | | --------------------- | ----------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account is activated. If **false** is returned, the account is not activated.| +| Promise<boolean> | Promise used to return the result. The value **true** means the account is activated; the value **false** means the opposite.| **Example**: Check whether OS account 100 is activated. @@ -2863,7 +2863,7 @@ Checks whether the specified constraint is enabled for an OS account. This API u | ---------- | ---------------------------- | ---- | ----------------------------------------------------------------- | | localId | number | Yes | ID of the target OS account. | | constraint | string | Yes | [Constraint](#constraints) to check. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the constraint is enabled. If **false** is returned, the constraint is not enabled.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| **Example**: Check whether OS account 100 is forbidden to use Wi-Fi. @@ -2905,7 +2905,7 @@ Checks whether the specified constraint is enabled for an OS account. This API u | Type | Description | | ---------------------- | --------------------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the constraint is enabled. If **false** is returned, the constraint is not enabled.| +| Promise<boolean> | Promise used to return the result. The value **true** means the specified constraint is enabled; the value **false** means the opposite.| **Example**: Check whether OS account 100 is forbidden to use Wi-Fi. @@ -2936,7 +2936,7 @@ Checks whether this OS account is a test account. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | --------------------------------------------------------------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account is a test account. If **false** is returned, the account is not a test account.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| **Example** @@ -2967,7 +2967,7 @@ Checks whether this OS account is a test account. This API uses a promise to ret | Type | Description | | ---------------------- | ------------------------------------------------------------------------ | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account is a test account. If **false** is returned, the account is not a test account.| +| Promise<boolean> | Promise used to return the result. The value **true** means the account is a test account; the value **false** means the opposite.| **Example** @@ -2998,7 +2998,7 @@ Checks whether this OS account has been verified. This API uses an asynchronous | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| **Example** @@ -3031,8 +3031,8 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- | -| localId | number | No | ID of the target OS account. | -| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| localId | number | Yes | ID of the target OS account. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| **Example** @@ -3072,7 +3072,7 @@ Checks whether an OS account has been verified. This API uses a promise to retur | Type | Description | | ---------------------- | ----------------------------------------------------------------- | -| Promise<boolean> | Promise used to return the result. If **true** is returned, the account has been verified. If **false** is returned, the account has not been verified.| +| Promise<boolean> | Promise used to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| **Example** @@ -3337,7 +3337,7 @@ Obtains the OS account ID based on the domain account information. This API uses | Type | Description | | :-------------------- | :------------------------------------- | -| Promise<number> | Promise used to return the OS account ID obtained.| +| Promise<number> | Promise used to return the ID of the OS account associated with the domain account.| **Example** @@ -3985,7 +3985,7 @@ Obtains the executor property based on the request. This API uses a promise to r ### setProperty8+ -setProperty(request: SetPropertyRequest, callback: AsyncCallback<number>): void; +setProperty(request: SetPropertyRequest, callback: AsyncCallback<void>): void; Sets the property for the initialization algorithm. This API uses an asynchronous callback to return the result. @@ -4000,7 +4000,7 @@ Sets the property for the initialization algorithm. This API uses an asynchronou | Name | Type | Mandatory| Description | | -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------- | | request | [SetPropertyRequest](#setpropertyrequest8)| Yes | Request information, including the authentication credential type and the key value to set. | -| callback | AsyncCallback<number> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a [result code](#resultcode8). Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| **Error codes** @@ -4018,9 +4018,12 @@ Sets the property for the initialization algorithm. This API uses an asynchronou setInfo: new Uint8Array([0]) }; try { - userAuth.setProperty(request, (err, result) => { - console.log('setProperty error = ' + JSON.stringify(err)); - console.log('setProperty result = ' + JSON.stringify(result)); + userAuth.setProperty(request, (err) => { + if (err) { + console.log('setProperty failed, error = ' + JSON.stringify(err)); + } else { + console.log('setProperty successfully'); + } }); } catch (e) { console.log('setProperty exception = ' + JSON.stringify(e)); @@ -4029,7 +4032,7 @@ Sets the property for the initialization algorithm. This API uses an asynchronou ### setProperty8+ -setProperty(request: SetPropertyRequest): Promise<number>; +setProperty(request: SetPropertyRequest): Promise<void>; Sets the property for the initialization algorithm. This API uses a promise to return the result. @@ -4049,7 +4052,7 @@ Sets the property for the initialization algorithm. This API uses a promise to r | Type | Description | | :-------------------- | :------------------------------------------------------------ | -| Promise<number> | Promise used to return the [result code](#resultcode8).| +| Promise<void> | Promise that returns no value.| **Error codes** @@ -4067,10 +4070,10 @@ Sets the property for the initialization algorithm. This API uses a promise to r setInfo: new Uint8Array([0]) }; try { - userAuth.setProperty(request).then((result) => { - console.log('setProperty result = ' + JSON.stringify(result)); + userAuth.setProperty(request).then(() => { + console.log('setProperty successfully'); }).catch((err) => { - console.log('setProperty error = ' + JSON.stringify(err)); + console.log('setProperty failed, error = ' + JSON.stringify(err)); }); } catch (e) { console.log('setProperty exception = ' + JSON.stringify(e)); @@ -4081,7 +4084,7 @@ Sets the property for the initialization algorithm. This API uses a promise to r auth(challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; -Performs authentication for the current user. This API uses a callback to return the result. +Performs authentication of the current user. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -4139,7 +4142,7 @@ Performs authentication for the current user. This API uses a callback to return authUser(userId: number, challenge: Uint8Array, authType: AuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array; -Performs authentication for a user. This API uses an asynchronous callback to return the result. +Performs authentication of the specified user. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -4493,7 +4496,7 @@ Updates credential information. This API uses a callback to return the result. | Name | Type | Mandatory| Description | | --------------- | ------------------------------------- | --- | ------------------------- | -| credentialInfo | [CredentialInfo](#credentialinfo8) | Yes | New credential information. | +| credentialInfo | [CredentialInfo](#credentialinfo8) | Yes | New credential information. | | callback | [IIdmCallback](#iidmcallback8) | Yes | Callback invoked to return the new credential information.| **Error codes** @@ -4701,7 +4704,7 @@ Obtains authentication information. This API uses an asynchronous callback to re | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------------------ | ---- | --------------------------------------------- | -| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential information obtained. Otherwise, **err** is an error object.| +| callback | AsyncCallback<Array<[EnrolledCredInfo](#enrolledcredinfo8)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is information about all registered credentials of the user. Otherwise, **err** is an error object.| **Error codes** @@ -4974,7 +4977,7 @@ Called to return the result code and request result information. | Name | Type | Mandatory| Description | | --------- | --------------------------------------- | ---- | ----------------------- | | result | number | Yes | Authentication result code. | -| extraInfo | [AuthResult](#authresult8) | Yes | Specific information to be transferred.| +| extraInfo | [RequestResult](#requestresult8) | Yes | Specific information to be transferred.| **Example** ```js @@ -5124,7 +5127,7 @@ Enumerates the types of properties to obtain. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ------------- | ------ | --------- | | AUTH_SUB_TYPE | 1 | Authentication credential subtype.| | REMAIN_TIMES | 2 | Remaining time. | @@ -5138,7 +5141,7 @@ Enumerates the types of properties to set. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | -------------- | ----- | ----------- | | INIT_ALGORITHM | 1 | Initialization algorithm.| @@ -5150,7 +5153,7 @@ Enumerates the authentication credential types. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ----- | ----- | ---------------- | | PIN | 1 | PIN authentication.| | FACE | 2 | Facial authentication.| @@ -5163,7 +5166,7 @@ Enumerates the authentication credential subtypes. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ---------- | ----- | ------------------ | | PIN_SIX | 10000 | Six-digit PIN. | | PIN_NUMBER | 10001 | Custom PIN.| @@ -5179,7 +5182,7 @@ Enumerates the trust levels of the authentication result. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ---- | ------ | ----------- | | ATL1 | 10000 | Trust level 1.| | ATL2 | 20000 | Trust level 2.| @@ -5194,7 +5197,7 @@ Enumerates the modules from which information is obtained. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | --------- | ------ | ------------------------ | | FACE_AUTH | 1 | Facial authentication module.| @@ -5206,7 +5209,7 @@ Enumerates the authentication result codes. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ----------------------- | ----- | ---------------------------------------- | | SUCCESS | 0 | The authentication is successful or the authentication feature is supported. | | FAIL | 1 | The authentication executor failed to identify the user. | @@ -5228,7 +5231,7 @@ Enumerates the tip codes for facial authentication. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ----------------------------- | ----- | ---------------------------------------- | | FACE_AUTH_TIP_TOO_BRIGHT | 1 | The obtained face image is too bright. | | FACE_AUTH_TIP_TOO_DARK | 2 | The obtained face image is too dark. | @@ -5250,7 +5253,7 @@ Enumerates the tip codes for fingerprint authentication. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ----------------------------- | ----- | ----------------------------------------------- | | FINGERPRINT_TIP_GOOD | 0 | The captured image is clear. | | FINGERPRINT_TIP_IMAGER_DIRTY | 1 | The fingerprint image has big noise due to dirt on the sensor.| @@ -5381,10 +5384,9 @@ Enumerates the constraint sources. **System capability**: SystemCapability.Account.OsAccount -| Name | Default Value| Description | +| Name | Value| Description | | ------ | ------ | ------------ | | CONSTRAINT_NOT_EXIST | 0 | The constraint does not exist.| | CONSTRAINT_TYPE_BASE | 1 | Constraint from system settings. | | CONSTRAINT_TYPE_DEVICE_OWNER | 2 | Constraint from the device owners' settings. | | CONSTRAINT_TYPE_PROFILE_OWNER | 3 | Constraint from the profile owners' settings. | -