# 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. > **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_appAccount from '@ohos.account.appAccount'; ``` ## account_appAccount.createAppAccountManager createAppAccountManager(): AppAccountManager Creates an **AppAccountManager** instance. **System capability**: SystemCapability.Account.AppAccount **Return value** | Type | Description | | ----------------- | ------------ | | AppAccountManager | **AppAccountManager** instance created.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); ``` ## AppAccountManager Provides methods to manage app accounts. ### addAccount addAccount(name: string, callback: AsyncCallback<void>): void Adds an app account to the **AppAccountManager** service. 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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.addAccount("WangWu", (err) => { console.log("addAccount err: " + JSON.stringify(err)); }); ``` ### addAccount addAccount(name: string, extraInfo: string, 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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | 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. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.addAccount("LiSi", "token101", (err) => { console.log("addAccount err: " + JSON.stringify(err)); }); ``` ### 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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | 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.| **Return value** | Type | Description | | ------------------- | --------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### addAccountImplicitly8+ addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void 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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | 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. | **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)); }); } const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.addAccountImplicitly("LiSi", "readAge", {}, { onResult: onResultCallback, onRequestRedirected: onRequestRedirectedCallback }); ``` ### deleteAccount deleteAccount(name: string, callback: AsyncCallback<void>): void Deletes an app account from the **AppAccountManager** service. 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 delete. | | callback | AsyncCallback<void> | Yes | Callback invoked when the app account is deleted.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.deleteAccount("ZhaoLiu", (err) => { console.log("deleteAccount err: " + JSON.stringify(err)); }); ``` ### deleteAccount deleteAccount(name: string): Promise<void> Deletes an app account from the **AppAccountManager** service. 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 app account to delete.| **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.deleteAccount("ZhaoLiu").then(() => { console.log('deleteAccount Success'); }).catch((err) => { console.log("deleteAccount err: " + JSON.stringify(err)); }); ``` ### disableAppAccess disableAppAccess(name: string, bundleName: string, 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. **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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { console.log("disableAppAccess err: " + JSON.stringify(err)); }); ``` ### disableAppAccess disableAppAccess(name: string, bundleName: string): Promise<void> Disables an app account from accessing an app with the given bundle name. 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. | **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### enableAppAccess enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void Enables an app account to access an app with the given bundle name. 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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { console.log("enableAppAccess: " + JSON.stringify(err)); }); ``` ### enableAppAccess enableAppAccess(name: string, bundleName: string): Promise<void> Enables an app account to access an app with the given bundle name. 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.| **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js app_account_instance.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { console.log('enableAppAccess Success'); }).catch((err) => { console.log("enableAppAccess err: " + JSON.stringify(err)); }); ``` ### checkAppAccountSyncEnable checkAppAccountSyncEnable(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. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------- | ---- | --------------------- | | name | string | Yes | Name of the target app account. | | callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); console.log('checkAppAccountSyncEnable result: ' + result); }); ``` ### checkAppAccountSyncEnable checkAppAccountSyncEnable(name: string): Promise<boolean> Checks whether an app account allows app data synchronization. This API uses a promise to return the result. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **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.| **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)); }); ``` ### setAccountCredential setAccountCredential(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. **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 set. | | credential | string | Yes | Credential to set. | | callback | AsyncCallback<void> | Yes | Callback used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { console.log("setAccountCredential err: " + JSON.stringify(err)); }); ``` ### setAccountCredential setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> Sets a credential 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. | | credentialType | string | Yes | Type of the credential to set.| | credential | string | Yes | Credential to set. | **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### setAccountExtraInfo 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. **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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { console.log("setAccountExtraInfo err: " + JSON.stringify(err)); }); ``` ### setAccountExtraInfo setAccountExtraInfo(name: string, extraInfo: string): Promise<void> Sets additional information 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. | | extraInfo | string | Yes | Additional information to set.| **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### setAppAccountSyncEnable setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void Sets whether to enable app data synchronization for an app account. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); }); ``` ### setAppAccountSyncEnable setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> Sets whether to enable app data synchronization for an app account. This API uses a promise to return the result. **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications) **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.| **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### setAssociatedData 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. **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.| **Example** ```js app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) => { console.log("setAssociatedData err: " + JSON.stringify(err)); }); ``` ### setAssociatedData 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. **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. | **Return value** | Type | Description | | :------------------ | :-------------------- | | Promise<void> | Promise used to return the result.| **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)); }); ``` ### getAccountCredential getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 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. **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.| **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); }); ``` ### getAccountCredential getAccountCredential(name: string, credentialType: string): Promise<string> 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. | | credentialType | string | Yes | Type of the credential to obtain.| **Return value** | Type | Description | | :-------------------- | :-------------------- | | Promise<string> | Promise used to return the result.| **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)); }); ``` ### getAccountExtraInfo getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void 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. **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 additional information of the specified app account.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { console.log("getAccountExtraInfo err: " + JSON.stringify(err)); console.log('getAccountExtraInfo result: ' + result); }); ``` ### getAccountExtraInfo getAccountExtraInfo(name: string): Promise<string> Obtains additional information 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.| **Return value** | Type | Description | | :-------------------- | :-------------------- | | Promise<string> | Promise used to return the result.| **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)); }); ``` ### getAssociatedData 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. **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.| **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); }); ``` ### getAssociatedData getAssociatedData(name: string, key: string): Promise<string> Obtains data associated with 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. | | key | string | Yes | Key of the data to obtain.| **Return value** | Type | Description | | :-------------------- | :-------------------- | | Promise<string> | Promise used to return the result.| **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)); }); ``` ### getAllAccessibleAccounts getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 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 (available only to system applications) **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.| **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)); }); ``` ### getAllAccessibleAccounts getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> Obtains information about all accessible app accounts. 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** | 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.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.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.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. **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](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the authentication 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)); }); } const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "readAge", {}, { onResult: onResultCallback, onRequestRedirected: onRequestRedirectedCallback }); ``` ### getOAuthToken8+ getOAuthToken(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. **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. | | callback | AsyncCallback<string> | Yes | Callback invoked to return the result. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", (err, data) => { console.log('getOAuthToken err: ' + JSON.stringify(err)); console.log('getOAuthToken token: ' + data); }); ``` ### getOAuthToken8+ getOAuthToken(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. **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. | **Parameters** | Type | Description | | --------------------- | --------------------- | | Promise<string> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge").then((data) => { console.log('getOAuthToken token: ' + data); }).catch((err) => { console.log("getOAuthToken err: " + JSON.stringify(err)); }); ``` ### setOAuthToken8+ setOAuthToken(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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | -------- | | 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.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx", (err) => { console.log('setOAuthToken err: ' + JSON.stringify(err)); }); ``` ### setOAuthToken8+ setOAuthToken(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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | -------- | ------ | ---- | -------- | | name | string | Yes | Name of the target app account.| | authType | string | Yes | Authentication type. | | token | string | Yes | OAuth token to set.| **Parameters** | Type | Description | | ------------------- | --------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx").then(() => { console.log('setOAuthToken successfully'); }).catch((err) => { console.log('setOAuthToken err: ' + JSON.stringify(err)); }); ``` ### deleteOAuthToken8+ deleteOAuthToken(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. **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. | | token | string | Yes | OAuth token to delete.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx", (err) => { console.log('deleteOAuthToken err: ' + JSON.stringify(err)); }); ``` ### deleteOAuthToken8+ deleteOAuthToken(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. **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. | | token | string | Yes | OAuth token to delete.| **Parameters** | Type | Description | | ------------------- | --------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx").then(() => { console.log('deleteOAuthToken successfully'); }).catch((err) => { console.log("deleteOAuthToken err: " + JSON.stringify(err)); }); ``` ### setOAuthTokenVisibility8+ setOAuthTokenVisibility(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. **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. The value **true** means visible, and the value **false** means the opposite.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err) => { console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` ### setOAuthTokenVisibility8+ setOAuthTokenVisibility(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. **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. | **Parameters** | Type | Description | | ------------------- | --------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then(() => { console.log('setOAuthTokenVisibility successfully'); }).catch((err) => { console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` ### checkOAuthTokenVisibility8+ checkOAuthTokenVisibility(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. **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.| | callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err, data) => { console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); console.log('checkOAuthTokenVisibility isVisible: ' + data); }); ``` ### checkOAuthTokenVisibility8+ checkOAuthTokenVisibility(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. **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.| **Parameters** | Type | Description | | ---------------------- | --------------------- | | Promise<boolean> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then((data) => { console.log('checkOAuthTokenVisibility isVisible: ' + data); }).catch((err) => { console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); }); ``` ### getAllOAuthTokens8+ getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void Obtains all OAuth tokens visible to the caller 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. | | 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. | **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)); }); ``` ### getAllOAuthTokens8+ getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> Obtains all OAuth tokens visible to the caller 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. | | owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| **Parameters** | Type | Description | | ---------------------------------------- | --------------------- | | Promise<Array< [OAuthTokenInfo](#oauthtokeninfo8)>> | Promise used to return the result.| **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)); }); ``` ### getOAuthList8+ getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void Obtains a list of authorized OAuth tokens 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. | | authType | string | Yes | Authorization type.| | callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge", (err, data) => { console.log('getOAuthList err: ' + JSON.stringify(err)); console.log('getOAuthList data: ' + JSON.stringify(data)); }); ``` ### getOAuthList8+ getOAuthList(name: string, authType: string): Promise<Array<string>> Obtains a list of authorized OAuth tokens 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. | | authType | string | Yes | Authorization type.| **Parameters** | Type | Description | | ---------------------------------- | --------------------- | | Promise<Array<string>> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge").then((data) => { console.log('getOAuthList data: ' + JSON.stringify(data)); }).catch((err) => { console.log("getOAuthList err: " + JSON.stringify(err)); }); ``` ### getAuthenticatorCallback8+ getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void Obtains the authenticator callback for an 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<[AuthenticatorCallback](#authenticatorcallback8)> | Yes | Callback invoked to return the result.| **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]: "readAge", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; callback.OnResult(account_appAccount.ResultCode.SUCCESS, result); }); }); ``` ### getAuthenticatorCallback8+ getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> Obtains the authenticator callback for an 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.| **Parameters** | Type | Description | | ------------------------------------ | --------------------- | | Promise<[AuthenticatorCallback](#authenticatorcallback8)> | Promise used to return the result.| **Example** ```js 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]: "readAge", [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)); }); ``` ### getAuthenticatorInfo8+ getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void Obtains authenticator information of an app account. 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 | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. | **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)); }); ``` ### getAuthenticatorInfo8+ getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> Obtains authenticator information of an app account. This API uses a promise 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.| **Parameters** | Type | Description | | -------------------------------- | --------------------- | | Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => { console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); }).catch((err) => { console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); }); ``` ### checkAppAccess9+ checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void Checks whether an app account is authorized to access 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 to access.| | callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | **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)); }); ``` ### checkAppAccess9+ checkAppAccess(name: string, bundleName: string): Promise<boolean> Checks whether an app account is authorized to access 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 to access.| **Parameters** | Type | Description | | ---------------------- | --------------------------------- | | Promise<boolean> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { console.log('checkAppAccess: ' + JSON.stringify(data)); }).catch((err) => { console.log("checkAppAccess err: " + JSON.stringify(err)); }); ``` ### deleteAccountCredential9+ deleteAccountCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void Deletes 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.| | credentialType | string | Yes | Type of the credential to delete. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| **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)); }); ``` ### deleteAccountCredential9+ deleteAccountCredential(name: string, credentialType: string): Promise<void> Deletes 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.| | credentialType | string | Yes | Type of the credential to delete. | **Parameters** | Type | Description | | ------------------- | -------------------------------- | | Promise<void> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.deleteAccountCredential("zhangsan", "pin").then((data) => { console.log('deleteAccountCredential: ' + JSON.stringify(data)); }).catch((err) => { console.log("deleteAccountCredential err: " + 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. **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. | **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => { console.log('checkAccountLabels: ' + JSON.stringify(data)); console.log("checkAccountLabels err: " + 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. **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. | **Parameters** | Type | Description | | ------------------- | -------------------------------- | | Promise<boolean> | Promise used to return the result.| **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { console.log('checkAccountLabels: ' + JSON.stringify(data)); }).catch((err) => { console.log("checkAccountLabels err: " + JSON.stringify(err)); }); ``` ### selectAccountsByOptions9+ selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>); Selects the accounts accessible to the requester based on the options. This API uses an asynchronous callback to return the result. **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. | **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)); }); ``` ### selectAccountsByOptions9+ selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> Selects the accounts accessible to the requester based on the options. This API uses a promise to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | -------------- | ------------------------- | ----- | --------------- | | options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | **Parameters** | Type | Description | | ------------------- | -------------------------------- | | Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the result.| **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)); }).catch((err) => { console.log("selectAccountsByOptions err: " + JSON.stringify(err)); }); ``` ### verifyCredential9+ verifyCredential(name: string, owner: string, callback: AuthenticatorCallback): 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. | | callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| **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)); } }); ``` ### verifyCredential9+ verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): 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 | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| **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)); } }); ``` ### setAuthenticatorProperties9+ setAuthenticatorProperties(owner: string, callback: AuthenticatorCallback): void; Sets 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 | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| **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)); } }); ``` ### setAuthenticatorProperties9+ setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthenticatorCallback): void; Sets 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 | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| **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)); } }); ``` ## AppAccountInfo Defines app account information. **System capability**: SystemCapability.Account.AppAccount | 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 target app account. | ## OAuthTokenInfo8+ Defines OAuth token information. **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.| ## AuthenticatorInfo8+ Defines OAuth authenticator information. **System capability**: SystemCapability.Account.AppAccount | Name | Type | Mandatory | Description | | ------- | ------ | ---- | ---------- | | owner | string | Yes | Owner of the authenticator. The value is the bundle name of the app.| | iconId | string | Yes | ID of the authenticator icon. | | labelId | string | Yes | ID of the authenticator label. | ## SelectAccountsOptions9+ Represents the options for selecting accounts. **System capability**: SystemCapability.Account.AppAccount | Name | Type | Mandatory | Description | | --------------- | --------------------------- | ----- | ------------------- | | allowedAccounts | Array<[AppAccountInfo](#appaccountinfo)> | No | Allowed accounts. | | allowedOwners | Array<string> | No | Allowed account owners.| | requiredLabels | Array<string> | No | Labels required for the authenticator. | ## VerifyCredentialOptions9+ Represents the options for verifying the user credential. **System capability**: SystemCapability.Account.AppAccount | Name | Type | Mandatory | Description | | -------------- | ---------------------- | ----- | -------------- | | credentialType | string | No | Type of the credential to verify. | | credential | string | No | Credential value. | | parameters | {[key:string]: Object} | No | Customized parameters.| ## SetPropertiesOptions9+ Represents the options for setting authenticator properties. **System capability**: SystemCapability.Account.AppAccount | Name | Type | Mandatory | Description | | ---------- | ---------------------- | ----- | -------------- | | properties | {[key:string]: Object} | No | Authenticator properties. | | parameters | {[key:string]: Object} | No | Customized parameters.| ## Constants8+ Enumerates the constants. **System capability**: SystemCapability.Account.AppAccount | Name | Default 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.| | KEY_TOKEN | "token" | Token. | | KEY_ACTION | "action" | Operation. | | KEY_AUTH_TYPE | "authType" | Authentication type. | | KEY_SESSION_ID | "sessionId" | Session ID. | | KEY_CALLER_PID | "callerPid" | PID of the caller. | | KEY_CALLER_UID | "callerUid" | UID of the caller. | | KEY_CALLER_BUNDLE_NAME | "callerBundleName" | Bundle name of the caller. | | KEY_REQUIRED_LABELS9+ | "requiredLabels" | Required labels. | | KEY_BOOLEAN_RESULT9+ | "booleanResult" | Return value of the Boolean type. | ## ResultCode8+ Enumerates the result codes. **System capability**: SystemCapability.Account.AppAccount | Name | Default Value | Description | | ----------------------------------- | ----- | ------------ | | SUCCESS | 0 | The operation is successful. | | ERROR_ACCOUNT_NOT_EXIST | 10001 | The app account does not exist. | | ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. | | ERROR_INVALID_PASSWORD | 10003 | The password is invalid. | | ERROR_INVALID_REQUEST | 10004 | The request is invalid. | | ERROR_INVALID_RESPONSE | 10005 | The response is invalid. | | ERROR_NETWORK_EXCEPTION | 10006 | The network is abnormal. | | ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist. | | ERROR_OAUTH_CANCELED | 10008 | The authentication is canceled. | | ERROR_OAUTH_LIST_TOO_LARGE | 10009 | The size of the OAuth list exceeds the limit. | | ERROR_OAUTH_SERVICE_BUSY | 10010 | The OAuth service is busy. | | 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_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+ Provides OAuth authenticator callbacks. ### onResult8+ onResult: (code: number, result: {[key: string]: any}) => 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 | {[key: string]: any} | Yes | Authentication result. | **Example** ```js const 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_AUTH_TYPE]: "readAge", [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; callback.OnResult(account_appAccount.ResultCode.SUCCESS, result); }).catch((err) => { console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); }); ``` ### onRequestRedirected8+ 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 { addAccountImplicitly(authType, callerBundleName, options, callback) { callback.onRequestRedirected({ bundleName: "com.example.ohos.accountjsdemo", abilityName: "com.example.ohos.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); } } ``` ### onRequestContinued9+ onRequestContinued?: () => void Called to continue to process the request. **System capability**: SystemCapability.Account.AppAccount **Example** ```js const appAccountManager = account_appAccount.createAppAccountManager(); var sessionId = "1234"; appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { callback.OnRequestContinued(); }).catch((err) => { console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); }); ``` ## Authenticator8+ Provides APIs to operate the authenticator. ### addAccountImplicitly8+ 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. **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | ---------------- | --------------------- | ---- | --------------- | | 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.| ### authenticate8+ authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void Authenticates an app account to obtain the OAuth access 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 | 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.| ### verifyCredential9+ verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): 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. | | options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for credential verification. | | callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the verification result.| ### setProperties9+ setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback): void; Sets authenticator properties. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Account.AppAccount **Parameters** | Name | Type | Mandatory | Description | | ---------------- | --------------------- | ---- | --------------- | | options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | | callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| ### checkAccountLabels9+ checkAccountLabels(name: string, labels: Array<string>, callback: AuthenticatorCallback): void; Checks the account labels. 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. | | labels | Array<string> | Yes | Labels to check. | | callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the check result.| ### isAccountRemovable9+ isAccountRemovable(name: string, callback: AuthenticatorCallback): void; Checks whether an app account can be deleted. 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. | | callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes | Authenticator callback invoked to return the result.| ### getRemoteObject9+ getRemoteObject(): rpc.RemoteObject; Obtains the remote object of an authenticator. This API cannot be overloaded. **System capability**: SystemCapability.Account.AppAccount **Example** ```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", }); } 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: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback) { callback.onRequestRedirected({ bundleName: "com.example.ohos.accountjsdemo", abilityName: "com.example.ohos.accountjsdemo.VerifyAbility", parameters: { name: name } }); } setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback) { callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); } checkAccountLabels(name: string, labels: Array, callback: AuthenticatorCallback) { 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(); } } ```