@ohos.account.appAccount (Application Account Management)
The appAccount module provides APIs for adding, deleting, modifying, and querying application account information, and supports inter-application authentication and distributed data synchronization.
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
import { appAccount } from '@kit.BasicServicesKit';
appAccount.createAppAccountManager
createAppAccountManager(): AppAccountManager
Creates an AppAccountManager object.
System capability: SystemCapability.Account.AppAccount
Return value
| Type | Description |
|---|---|
| AppAccountManager | AppAccountManager object created. |
Example
let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
AppAccountManager
Defines the application account manager, which is used to manage account information of applications.
createAccount9+
createAccount(name: string, callback: AsyncCallback<void>): void
Creates an application account with the given 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 application account. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.createAccount('WangWu', (err: BusinessError) => {
if (err) {
console.error(`createAccount code: code is ${err.code}, message is ${err.message}`);
} else {
console.info('createAccount successful.');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`createAccount err: code is ${err.code}, message is ${err.message}`);
}
createAccount9+
createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void
Creates an application account with custom data. 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 application account. |
| options | CreateAccountOptions | Yes | Options for creating the application 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 used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or options. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.CreateAccountOptions = {
customData: {
age: '10'
}
}
try {
appAccountManager.createAccount('LiSi', options, (err: BusinessError) => {
if (err) {
console.error(`createAccount failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('createAccount successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`createAccount exception: code is ${err.code}, message is ${err.message}`);
}
createAccount9+
createAccount(name: string, options?: CreateAccountOptions): Promise<void>
Creates an application account with custom data. 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 application account. |
| options | CreateAccountOptions | No | Options for creating the application account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens). By default, no value is passed in, which means no additional information needs to be added for the account. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or options. |
| 12300004 | Account already exists. |
| 12300007 | The number of accounts reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.CreateAccountOptions = {
customData: {
age: '10'
}
}
try {
appAccountManager.createAccount('LiSi', options).then(() => {
console.info('createAccount successfully');
}).catch((err: BusinessError) => {
console.error(`createAccount failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`createAccount exception: code is ${err.code}, message is ${err.message}`);
}
createAccountImplicitly9+
createAccountImplicitly(owner: string, callback: AuthCallback): void
Creates an application 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 application account. The value is the bundle name of the application. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 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
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, result?: appAccount.AuthResult): void {
console.info('resultCode: ' + code);
console.info('result: ' + JSON.stringify(result));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
try {
appAccountManager.createAccountImplicitly('com.example.accountjsdemo', {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
} catch (e) {
const err = e as BusinessError;
console.error(`createAccountImplicitly exception: code is ${err.code}, message is ${err.message}`);
}
}
build() {}
}
createAccountImplicitly9+
createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void
Creates an application 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
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| options | CreateAccountImplicitlyOptions | Yes | Options for implicitly creating the account. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner 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
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, result?: appAccount.AuthResult): void {
console.info('resultCode: ' + code);
console.info('result: ' + JSON.stringify(result));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
let options: appAccount.CreateAccountImplicitlyOptions = {
authType: 'getSocialData',
requiredLabels: ['student']
};
try {
appAccountManager.createAccountImplicitly('com.example.accountjsdemo', options, {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
} catch (e) {
const err = e as BusinessError;
console.error(`createAccountImplicitly exception: code is ${err.code}, message is ${err.message}`);
}
}
build() {}
}
removeAccount9+
removeAccount(name: string, callback: AsyncCallback<void>): void
Removes an application 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 application account. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.removeAccount('ZhaoLiu', (err: BusinessError) => {
if (err) {
console.error(`removeAccount failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('removeAccount successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`removeAccount exception: code is ${err.code}, message is ${err.message}`);
}
removeAccount9+
removeAccount(name: string): Promise<void>
Removes an application 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 application account. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.removeAccount('Lisi').then(() => {
console.info('removeAccount successfully');
}).catch((err: BusinessError) => {
console.error(`removeAccount failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`removeAccount exception: code is ${err.code}, message is ${err.message}`);
}
setAppAccess9+
setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void
Sets the access to the data of an account for an application. 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 application account. |
| bundleName | string | Yes | Bundle name of the application. |
| 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 used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true, (err: BusinessError) => {
if (err) {
console.error(`setAppAccess failed: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAppAccess successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
setAppAccess9+
setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void>
Sets the access to the data of an account for an application. 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 application account. |
| bundleName | string | Yes | Bundle name of the application. |
| 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 that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAppAccess('ZhangSan', 'com.example.accountjsdemo', true).then(() => {
console.info('setAppAccess successfully');
}).catch((err: BusinessError) => {
console.error(`setAppAccess failed: code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
checkAppAccess9+
checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void
Checks whether an application can access the data of an 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 application account. |
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value true means the application can access the account data; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo',
(err: BusinessError, isAccessible: boolean) => {
if (err) {
console.error(`checkAppAccess failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkAppAccess successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
checkAppAccess9+
checkAppAccess(name: string, bundleName: string): Promise<boolean>
Checks whether an application can access the data of an 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 application account. |
| bundleName | string | Yes | Bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means the application can access the account data; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or bundleName. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkAppAccess('ZhangSan', 'com.example.accountjsdemo').then((isAccessible: boolean) => {
console.info('checkAppAccess successfully, isAccessible: ' + isAccessible);
}).catch((err: BusinessError) => {
console.error(`checkAppAccess failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAppAccess exception: code is ${err.code}, message is ${err.message}`);
}
setDataSyncEnabled9+
setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void
Sets data synchronization for an application 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 application account. |
| isEnabled | boolean | Yes | Whether to enable data synchronization. The value true means that data synchronization is enabled, and false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setDataSyncEnabled('ZhangSan', true, (err: BusinessError) => {
console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
setDataSyncEnabled9+
setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void>
Sets data synchronization for an application 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 application account. |
| isEnabled | boolean | Yes | Whether to enable data synchronization. The value true means that data synchronization is enabled, and false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setDataSyncEnabled('ZhangSan', true).then(() => {
console.info('setDataSyncEnabled Success');
}).catch((err: BusinessError) => {
console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
checkDataSyncEnabled9+
checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void
Checks whether data synchronization is enabled for an application 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 application account. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value true means data synchronization is enabled for the application account; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkDataSyncEnabled('ZhangSan', (err: BusinessError, isEnabled: boolean) => {
if (err) {
console.error(`checkDataSyncEnabled failed, err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
checkDataSyncEnabled9+
checkDataSyncEnabled(name: string): Promise<boolean>
Checks whether data synchronization is enabled for an application 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 application account. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means data synchronization is enabled for the application account; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkDataSyncEnabled('ZhangSan').then((isEnabled: boolean) => {
console.info('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled);
}).catch((err: BusinessError) => {
console.error(`checkDataSyncEnabled failed, err: code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkDataSyncEnabled err: code is ${err.code}, message is ${err.message}`);
}
setCredential9+
setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void
Sets a credential for an application 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 application account. |
| credentialType | string | Yes | Credential type. |
| credential | string | Yes | Credential value. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the credential is set successfully, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, credentialType or credential. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx', (err: BusinessError) => {
if (err) {
console.error(`setCredential failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('setCredential successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setCredential exception: code is ${err.code}, message is ${err.message}`);
}
setCredential9+
setCredential(name: string, credentialType: string, credential: string): Promise<void>
Sets a credential for an application 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 application account. |
| credentialType | string | Yes | Credential type. |
| credential | string | Yes | Credential value. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, credentialType or credential. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setCredential('ZhangSan', 'PIN_SIX', 'xxxxxx').then(() => {
console.info('setCredential successfully');
}).catch((err: BusinessError) => {
console.error(`setCredential failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setCredential exception: code is ${err.code}, message is ${err.message}`);
}
getCredential9+
getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void
Obtains the credential of an application 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 application account. |
| credentialType | string | Yes | Credential type. |
| callback | AsyncCallback<string> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getCredential('ZhangSan', 'PIN_SIX', (err: BusinessError, result: string) => {
if (err) {
console.error(`getCredential failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getCredential successfully, result: ' + result);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getCredential err: code is ${err.code}, message is ${err.message}`);
}
getCredential9+
getCredential(name: string, credentialType: string): Promise<string>
Obtains the credential of an application 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 application account. |
| credentialType | string | Yes | Credential type. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the credential obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getCredential('ZhangSan', 'PIN_SIX').then((credential: string) => {
console.info('getCredential successfully, credential: ' + credential);
}).catch((err: BusinessError) => {
console.error(`getCredential failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getCredential exception: code is ${err.code}, message is ${err.message}`);
}
setCustomData9+
setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void
Sets custom data for an application 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 application account. |
| key | string | Yes | Key of the custom data. |
| value | string | Yes | Value of the custom data. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, key or value. |
| 12300003 | Account not found. |
| 12400003 | The number of custom data reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setCustomData('ZhangSan', 'age', '12', (err: BusinessError) => {
if (err) {
console.error(`setCustomData failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('setCustomData successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setCustomData exception: code is ${err.code}, message is ${err.message}`);
}
setCustomData9+
setCustomData(name: string, key: string, value: string): Promise<void>
Sets custom data for an application 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 application account. |
| key | string | Yes | Key of the custom data. |
| value | string | Yes | Value of the custom data. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, key or value. |
| 12300003 | Account not found. |
| 12400003 | The number of custom data reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setCustomData('ZhangSan', 'age', '12').then(() => {
console.info('setCustomData successfully');
}).catch((err: BusinessError) => {
console.error(`setCustomData failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setCustomData exception: code is ${err.code}, message is ${err.message}`);
}
getCustomData9+
getCustomData(name: string, key: string, callback: AsyncCallback<string>): void
Obtains the custom data of an application 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 application account. |
| key | string | Yes | Key of the custom data. |
| callback | AsyncCallback<string> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getCustomData('ZhangSan', 'age', (err: BusinessError, data: string) => {
if (err) {
console.error('getCustomData failed, error: ' + err);
} else {
console.info('getCustomData successfully, data: ' + data);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getCustomData exception: code is ${err.code}, message is ${err.message}`);
}
getCustomData9+
getCustomData(name: string, key: string): Promise<string>
Obtains the custom data of an application 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 application account. |
| key | string | Yes | Key of the custom data. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the custom data value obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getCustomData('ZhangSan', 'age').then((data: string) => {
console.info('getCustomData successfully, data: ' + data);
}).catch((err: BusinessError) => {
console.error(`getCustomData failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getCustomData exception: code is ${err.code}, message is ${err.message}`);
}
getCustomDataSync9+
getCustomDataSync(name: string, key: string): string
Obtains the custom data of an application 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 application account. |
| key | string | Yes | Key of the custom data. |
Return value
| Type | Description |
|---|---|
| string | Value of the custom data. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or key. |
| 12300003 | Account not found. |
| 12400002 | Custom data not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
let value = appAccountManager.getCustomDataSync('ZhangSan', 'age');
console.info('getCustomDataSync successfully, value: ' + value);
} catch (e) {
const err = e as BusinessError;
console.error(`getCustomDataSync failed, code is ${err.code}, message is ${err.message}`);
}
getAllAccounts9+
getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void
Obtains information about all accessible application accounts. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<AppAccountInfo>> | Yes | Callback used to return the result. If the operation is successful, err is null and data is a list of accessible application accounts. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAllAccounts((err: BusinessError, data: appAccount.AppAccountInfo[]) => {
if (err) {
console.error(`getAllAccounts failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAllAccounts successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAllAccounts exception: code is ${err.code}, message is ${err.message}`);
}
getAllAccounts9+
getAllAccounts(): Promise<Array<AppAccountInfo>>
Obtains information about all accessible application accounts. This API uses a promise to return the result.
System capability: SystemCapability.Account.AppAccount
Return value
| Type | Description |
|---|---|
| Promise<Array<AppAccountInfo>> | Promise used to return information about all accessible accounts. |
Error codes
For details about the error codes, see Account Management Error Codes.
| ID | Error Message |
|---|---|
| 12300001 | System service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAllAccounts().then((data: appAccount.AppAccountInfo[]) => {
console.info('getAllAccounts successfully');
}).catch((err: BusinessError) => {
console.error(`getAllAccounts failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAllAccounts exception: code is ${err.code}, message is ${err.message}`);
}
getAccountsByOwner9+
getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void
Obtains the application accounts that can be accessed by the invoker based on the application 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 application account. The value is the bundle name of the application. |
| callback | AsyncCallback<Array<AppAccountInfo>> | Yes | Callback used to return the result. If the operation is successful, err is null and data is the application account information obtained. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAccountsByOwner('com.example.accountjsdemo2',
(err: BusinessError, data: appAccount.AppAccountInfo[]) => {
if (err) {
console.error(`getAccountsByOwner failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAccountsByOwner successfully, data:' + JSON.stringify(data));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAccountsByOwner exception:code is ${err.code}, message is ${err.message}`);
}
getAccountsByOwner9+
getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>>
Obtains the application accounts that can be accessed by the invoker based on the application account owner. 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 application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<Array<AppAccountInfo>> | Promise used to return the application account information obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAccountsByOwner('com.example.accountjsdemo2').then((
data: appAccount.AppAccountInfo[]) => {
console.info('getAccountsByOwner successfully, data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error(`getAccountsByOwner failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAccountsByOwner exception: code is ${err.code}, message is ${err.message}`);
}
on('accountChange')9+
on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void
Subscribes to account information changes of apps.
System capability: SystemCapability.Account.AppAccount
Parameters
| 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 application changes. |
| owners | Array<string> | Yes | Application bundle names of the account. |
| callback | Callback<Array<AppAccountInfo>> | Yes | Callback registered to return the list of changed application accounts. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid type or owners. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
console.info('receive change data:' + JSON.stringify(data));
}
try {
appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
const err = e as BusinessError;
console.error(`on accountChange failed, code is ${err.code}, message is ${err.message}`);
}
off('accountChange')9+
off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void
Unsubscribes from account information changes.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| type | 'accountChange' | Yes | Event type to unsubscribe from. The value is 'accountChange'. |
| callback | Callback<Array<AppAccountInfo>> | No | Callback to unregister. By default, no value is passed, which means to unregister all callbacks for the specified event. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid type. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
console.info('receive change data:' + JSON.stringify(data));
}
try {
appAccountManager.on('accountChange', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
const err = e as BusinessError;
console.error(`on accountChange failed, code is ${err.code}, message is ${err.message}`);
}
try {
appAccountManager.off('accountChange', changeOnCallback);
} catch (e) {
const err = e as BusinessError;
console.error(`off accountChange failed, code is ${err.code}, message is ${err.message}`);
}
auth9+
auth(name: string, owner: string, authType: string, callback: AuthCallback): void
Authenticates an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or authType. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, authResult?: appAccount.AuthResult): void {
console.info('resultCode: ' + code);
console.info('authResult: ' + JSON.stringify(authResult));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
try {
appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
} catch (e) {
const err = e as BusinessError;
console.error(`auth exception: code is ${err.code}, message is ${err.message}`);
}
}
build() {}
}
auth9+
auth(name: string, owner: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void
Authenticates an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| options | Record<string, Object> | Yes | Options for the authentication. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner, authType or options. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, authResult?: appAccount.AuthResult): void {
console.info('resultCode: ' + code);
console.info('authResult: ' + JSON.stringify(authResult));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
let options: Record<string, Object> = {
'password': 'xxxx',
};
try {
appAccountManager.auth('LiSi', 'com.example.accountjsdemo', 'getSocialData', options, {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
} catch (e) {
const err = e as BusinessError;
console.error(`auth exception: code is ${err.code}, message is ${err.message}`);
}
}
build() {}
}
getAuthToken9+
getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void
Obtains the authorization token of the specified authentication type for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| callback | AsyncCallback<string> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
(err: BusinessError, token: string) => {
if (err) {
console.error(`getAuthToken failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAuthToken successfully, token: ' + token);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
getAuthToken9+
getAuthToken(name: string, owner: string, authType: string): Promise<string>
Obtains the authorization token of the specified authentication type for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the authorization token obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((token: string) => {
console.info('getAuthToken successfully, token: ' + token);
}).catch((err: BusinessError) => {
console.error(`getAuthToken failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
setAuthToken9+
setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void
Sets an authorization token of the specific authentication type for an application 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 application account. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or token. |
| 12300003 | Account not found. |
| 12400004 | The number of tokens reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
if (err) {
console.error(`setAuthToken failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAuthToken successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
setAuthToken9+
setAuthToken(name: string, authType: string, token: string): Promise<void>
Sets an authorization token of the specific authentication type for an application 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 application account. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or token. |
| 12300003 | Account not found. |
| 12400004 | The number of tokens reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
console.info('setAuthToken successfully');
}).catch((err: BusinessError) => {
console.error(`setAuthToken failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
deleteAuthToken9+
deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void
Deletes the authorization token of the specified authentication type for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. If the token does not exist, no operation is performed. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner, authType or token. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
(err: BusinessError) => {
if (err) {
console.error(`deleteAuthToken failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('deleteAuthToken successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`deleteAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
deleteAuthToken9+
deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>
Deletes the authorization token of the specified authentication type for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. If the token does not exist, no operation is performed. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner, authType or token. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.deleteAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
console.info('deleteAuthToken successfully');
}).catch((err: BusinessError) => {
console.error(`deleteAuthToken failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`deleteAuthToken exception: code is ${err.code}, message is ${err.message}`);
}
setAuthTokenVisibility9+
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void
Sets the visibility of an authorization token to an application. 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 application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value true means the authorization token is visible to the application; the value false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
(err: BusinessError) => {
if (err) {
console.error(`setAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAuthTokenVisibility successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
setAuthTokenVisibility9+
setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>
Sets the visibility of an authorization token to an application. 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 application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value true means the authorization token is visible to the application; the value false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
| 12400005 | The size of authorization list reaches the upper limit. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
console.info('setAuthTokenVisibility successfully');
}).catch((err: BusinessError) => {
console.error(`setAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
checkAuthTokenVisibility9+
checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void
Checks the visibility of an authorization token of the specified authentication type to an application. 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 application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, err is null and data can be true (the authorization token is visible to the application) or false (the authorization token is not visible to the application). If the operation fails, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
(err: BusinessError, isVisible: boolean) => {
if (err) {
console.error(`checkAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
checkAuthTokenVisibility9+
checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>
Checks the visibility of an authorization token of the specified authentication type to an application. 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 application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means the authorization token is visible to the application; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, authType or bundleName. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.checkAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
isVisible: boolean) => {
console.info('checkAuthTokenVisibility successfully, isVisible: ' + isVisible);
}).catch((err: BusinessError) => {
console.error(`checkAuthTokenVisibility failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAuthTokenVisibility exception: code is ${err.code}, message is ${err.message}`);
}
getAllAuthTokens9+
getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void
Obtains all tokens visible to the invoker for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| callback | AsyncCallback<Array<AuthTokenInfo>> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo',
(err: BusinessError, tokenArr: appAccount.AuthTokenInfo[]) => {
if (err) {
console.error(`getAllAuthTokens failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAllAuthTokens successfully, tokenArr: ' + tokenArr);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAllAuthTokens exception: code is ${err.code}, message is ${err.message}`);
}
getAllAuthTokens9+
getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>>
Obtains all tokens visible to the invoker for an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<Array<AuthTokenInfo>> | Promise used to return the tokens obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or owner. |
| 12300003 | Account not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAllAuthTokens('LiSi', 'com.example.accountjsdemo').then((
tokenArr: appAccount.AuthTokenInfo[]) => {
console.info('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr));
}).catch((err: BusinessError) => {
console.error(`getAllAuthTokens failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAllAuthTokens exception: code is ${err.code}, message is ${err.message}`);
}
getAuthList9+
getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void
Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setAuthTokenVisibility. 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 application account. |
| authType | string | Yes | Authentication type. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAuthList('LiSi', 'getSocialData', (err: BusinessError, authList: string[]) => {
if (err) {
console.error(`getAuthList failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAuthList successfully, authList: ' + authList);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthList exception: code is ${err.code}, message is ${err.message}`);
}
getAuthList9+
getAuthList(name: string, authType: string): Promise<Array<string>>
Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setAuthTokenVisibility. 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 application account. |
| authType | string | Yes | Authentication type. |
Return value
| Type | Description |
|---|---|
| Promise<Array<string>> | Promise used to return a list of authorized bundles. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or authType. |
| 12300003 | Account not found. |
| 12300107 | AuthType not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.getAuthList('LiSi', 'getSocialData').then((authList: string[]) => {
console.info('getAuthList successfully, authList: ' + authList);
}).catch((err: BusinessError) => {
console.error(`getAuthList failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthList exception: code is ${err.code}, message is ${err.message}`);
}
getAuthCallback9+
getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): 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<AuthCallback> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid sessionId. |
| 12300108 | Session not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
try {
appAccountManager.getAuthCallback(sessionId, (err: BusinessError, callback: appAccount.AuthCallback) => {
if (err != null) {
console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
return;
}
let result: appAccount.AuthResult = {
account: {
name: 'Lisi',
owner: 'com.example.accountjsdemo',
},
tokenInfo: {
token: 'xxxxxx',
authType: 'getSocialData'
}
};
callback.onResult(0, result);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthCallback exception: code is ${err.code}, message is ${err.message}`);
}
}
}
getAuthCallback9+
getAuthCallback(sessionId: string): Promise<AuthCallback>
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. |
Return value
| Type | Description |
|---|---|
| Promise<AuthCallback> | Promise used to return the authenticator callback obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid sessionId. |
| 12300108 | Session not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
try {
appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
let result: appAccount.AuthResult = {
account: {
name: 'Lisi',
owner: 'com.example.accountjsdemo',
},
tokenInfo: {
token: 'xxxxxx',
authType: 'getSocialData'
}
};
callback.onResult(0, result);
}).catch((err: BusinessError) => {
console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`getAuthCallback exception: code is ${err.code}, message is ${err.message}`);
}
}
}
queryAuthenticatorInfo9+
queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void
Obtains the authenticator information of an application. 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 application account. The value is the bundle name of the application. |
| callback | AsyncCallback<AuthenticatorInfo> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300113 | Authenticator service not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo',
(err: BusinessError, info: appAccount.AuthenticatorInfo) => {
if (err) {
console.error(`queryAuthenticatorInfo failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`queryAuthenticatorInfo exception: code is ${err.code}, message is ${err.message}`);
}
queryAuthenticatorInfo9+
queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>
Obtains the authenticator information of an application. 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 application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<AuthenticatorInfo> | Promise used to return the authenticator information obtained. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300113 | Authenticator service not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.queryAuthenticatorInfo('com.example.accountjsdemo').then((
info: appAccount.AuthenticatorInfo) => {
console.info('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info));
}).catch((err: BusinessError) => {
console.error(`queryAuthenticatorInfo failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`queryAuthenticatorInfo exception: code is ${err.code}, message is ${err.message}`);
}
checkAccountLabels9+
checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void
Checks whether an application account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target application.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| labels | Array<string> | Yes | Labels to check. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, err is null and data can be true or false. The value true means the application account has the labels; the value false means the opposite. If the operation fails, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or labels. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let labels = ['student'];
try {
appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels,
(err: BusinessError, hasAllLabels: boolean) => {
if (err) {
console.error(`checkAccountLabels failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkAccountLabels successfully, hasAllLabels: ' + hasAllLabels);
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAccountLabels exception: code is ${err.code}, message is ${err.message}`);
}
checkAccountLabels9+
checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean>
Checks whether an application account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target application.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| labels | Array<string> | Yes | Labels to check. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means the application account has the labels; the value false means the opposite. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or labels. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let labels = ['student'];
try {
appAccountManager.checkAccountLabels('zhangsan', 'com.example.accountjsdemo', labels).then((
hasAllLabels: boolean) => {
console.info('checkAccountLabels successfully: ' + hasAllLabels);
}).catch((err: BusinessError) => {
console.error(`checkAccountLabels failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`checkAccountLabels exception: code is ${err.code}, message is ${err.message}`);
}
deleteCredential9+
deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void
Deletes the credential of the specified type from an application 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 application account. |
| credentialType | string | Yes | Credential type. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.deleteCredential('zhangsan', 'PIN_SIX', (err: BusinessError) => {
if (err) {
console.error(`deleteCredential failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('deleteCredential successfully');
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`deleteCredential exception: code is ${err.code}, message is ${err.message}`);
}
deleteCredential9+
deleteCredential(name: string, credentialType: string): Promise<void>
Deletes the credential of the specified type from an application 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 application account. |
| credentialType | string | Yes | Credential type. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name or credentialType. |
| 12300003 | Account not found. |
| 12300102 | Credential not found. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.deleteCredential('zhangsan', 'PIN_SIX').then(() => {
console.info('deleteCredential successfully');
}).catch((err: BusinessError) => {
console.error(`deleteCredential failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`deleteCredential exception: code is ${err.code}, message is ${err.message}`);
}
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 application 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>> | Yes | Callback used 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
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid options. |
| 12300010 | Account service busy. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.SelectAccountsOptions = {
allowedOwners: ['com.example.accountjsdemo'],
requiredLabels: ['student']
};
try {
appAccountManager.selectAccountsByOptions(options,
(err: BusinessError, accountArr: appAccount.AppAccountInfo[]) => {
if (err) {
console.error(`selectAccountsByOptions failed, code is ${err.code}, message is ${err.message}`);
} else {
console.info('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`selectAccountsByOptions exception: code is ${err.code}, message is ${err.message}`);
}
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 application provides the capability of checking the labels.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| options | SelectAccountsOptions | Yes | Options for selecting accounts. |
Return value
| Type | Description |
|---|---|
| Promise<Array<AppAccountInfo>> | Promise used to return the accounts selected. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid options. |
| 12300010 | Account service busy. |
| 12300114 | Authenticator service exception. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.SelectAccountsOptions = {
allowedOwners: ['com.example.accountjsdemo']
};
try {
appAccountManager.selectAccountsByOptions(options).then((accountArr: appAccount.AppAccountInfo[]) => {
console.info('selectAccountsByOptions successfully, accountArr: ' + JSON.stringify(accountArr));
}).catch((err: BusinessError) => {
console.error(`selectAccountsByOptions failed, code is ${err.code}, message is ${err.message}`);
});
} catch (e) {
const err = e as BusinessError;
console.error(`selectAccountsByOptions exception: code is ${err.code}, message is ${err.message}`);
}
verifyCredential9+
verifyCredential(name: string, owner: string, callback: AuthCallback): void
Verifies the credential of an application 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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| callback | AuthCallback | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 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
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', {
onResult: (resultCode: number, result?: appAccount.AuthResult) => {
console.info('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
console.info('verifyCredential onResult, result: ' + JSON.stringify(result));
},
onRequestRedirected: (request: Want) => {
console.info('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`verifyCredential err: code is ${err.code}, message is ${err.message}`);
}
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 application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| options | VerifyCredentialOptions | Yes | Options for credential verification. |
| callback | AuthCallback | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid name, owner or options. |
| 12300003 | Account not found. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.VerifyCredentialOptions = {
credentialType: 'pin',
credential: '123456'
};
try {
appAccountManager.verifyCredential('zhangsan', 'com.example.accountjsdemo', options, {
onResult: (resultCode: number, result?: appAccount.AuthResult) => {
console.info('verifyCredential onResult, resultCode: ' + JSON.stringify(resultCode));
console.info('verifyCredential onResult, result: ' + JSON.stringify(result));
},
onRequestRedirected: (request: Want) => {
console.info('verifyCredential onRequestRedirected, request: ' + JSON.stringify(request));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`verifyCredential err: code is ${err.code}, message is ${err.message}`);
}
setAuthenticatorProperties9+
setAuthenticatorProperties(owner: string, callback: AuthCallback): void
Sets the authenticator attributes of an application. 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. The value is the bundle name of the application. |
| callback | AuthCallback | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', {
onResult: (resultCode: number, result?: appAccount.AuthResult) => {
console.info('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
console.info('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
},
onRequestRedirected: (request: Want) => {
console.info('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthenticatorProperties err: code is ${err.code}, message is ${err.message}`);
}
setAuthenticatorProperties9+
setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void
Sets the 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. The value is the bundle name of the application. |
| options | SetPropertiesOptions | Yes | Authenticator properties to set. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Error codes
For details about the error codes, see Account Management Error Codes and Universal Error Codes.
| ID | Error Message |
|---|---|
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
| 12300001 | System service exception. |
| 12300002 | Invalid owner or options. |
| 12300010 | Account service busy. |
| 12300113 | Authenticator service not found. |
| 12300114 | Authenticator service exception. |
Example
import { Want } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
let options: appAccount.SetPropertiesOptions = {
properties: { prop1: 'value1' }
};
try {
appAccountManager.setAuthenticatorProperties('com.example.accountjsdemo', options, {
onResult: (resultCode: number, result?: appAccount.AuthResult) => {
console.info('setAuthenticatorProperties onResult, resultCode: ' + JSON.stringify(resultCode));
console.info('setAuthenticatorProperties onResult, result: ' + JSON.stringify(result));
},
onRequestRedirected: (request: Want) => {
console.info('setAuthenticatorProperties onRequestRedirected, request: ' + JSON.stringify(request));
}
});
} catch (e) {
const err = e as BusinessError;
console.error(`setAuthenticatorProperties err: code is ${err.code}, message is ${err.message}`);
}
addAccount(deprecated)
addAccount(name: string, callback: AsyncCallback<void>): void
Adds an application account with the given name. 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. Use createAccount instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.addAccount('WangWu', (err: BusinessError) => {
console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
addAccount(deprecated)
addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void
Adds an application 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. Use createAccount instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.addAccount('LiSi', 'token101', (err: BusinessError) => {
console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
addAccount(deprecated)
addAccount(name: string, extraInfo?: string): Promise<void>
Adds an application account name and additional 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. Use createAccount instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| extraInfo | string | No | Additional information (information that can be converted to the string type). The additional information cannot be sensitive information (such as the password and token) of the application account. By default, no value is passed, which means no additional information needs to be added for the account. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.addAccount('LiSi', 'token101').then(()=> {
console.info('addAccount Success');
}).catch((err: BusinessError) => {
console.error(`addAccount err: code is ${err.code}, message is ${err.message}`);
});
addAccountImplicitly(deprecated)
addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void
Adds an application 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. Use createAccountImplicitly instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. The authentication type is customized. |
| options | {[key: string]: any} | Yes | Options for the authentication, which can be set as required. |
| callback | AuthenticatorCallback | Yes | Authenticator callback used to return the result. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, result: Record<string, Object>): void {
console.info('resultCode: ' + code);
console.info('result: ' + JSON.stringify(result));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
appAccountManager.addAccountImplicitly('com.example.accountjsdemo', 'getSocialData', {}, {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
}
build() {}
}
deleteAccount(deprecated)
deleteAccount(name: string, callback: AsyncCallback<void>): void
Deletes an application 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. Use removeAccount instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.deleteAccount('ZhaoLiu', (err: BusinessError) => {
console.error(`deleteAccount err: code is ${err.code}, message is ${err.message}`);
});
deleteAccount(deprecated)
deleteAccount(name: string): Promise<void>
Deletes an application 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. Use removeAccount instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.deleteAccount('ZhaoLiu').then(() => {
console.info('deleteAccount Success');
}).catch((err: BusinessError) => {
console.error(`deleteAccount err: code is ${err.code}, message is ${err.message}`);
});
disableAppAccess(deprecated)
disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void
Disables an application account from accessing an application. 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. Use setAppAccess instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
console.error(`disableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
disableAppAccess(deprecated)
disableAppAccess(name: string, bundleName: string): Promise<void>
Disables an application account from accessing an application. This API uses a promise to return the result.
NOTE
This API is supported since API version 7 and deprecated since API version 9. Use setAppAccess instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the target application account. |
| bundleName | string | Yes | Bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.disableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
console.info('disableAppAccess Success');
}).catch((err: BusinessError) => {
console.error(`disableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
enableAppAccess(deprecated)
enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void
Enables an application account to access an application. 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. Use setAppAccess instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo', (err: BusinessError) => {
if (err) {
console.error(`enableAppAccess err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('enableAppAccess successful.');
}
});
enableAppAccess(deprecated)
enableAppAccess(name: string, bundleName: string): Promise<void>
Enables an application account to access an application. This API uses a promise to return the result.
NOTE
This API is supported since API version 7 and deprecated since API version 9. Use setAppAccess instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| bundleName | string | Yes | Bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.enableAppAccess('ZhangSan', 'com.example.accountjsdemo').then(() => {
console.info('enableAppAccess Success');
}).catch((err: BusinessError) => {
console.error(`enableAppAccess err: code is ${err.code}, message is ${err.message}`);
});
checkAppAccountSyncEnable(deprecated)
checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void
Checks whether data synchronization is enabled for an application 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. Use checkDataSyncEnabled instead.
Required permissions: ohos.permission.DISTRIBUTED_DATASYNC
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value true means data synchronization is enabled for the application account; the value false means the opposite. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.checkAppAccountSyncEnable('ZhangSan', (err: BusinessError, result: boolean) => {
if (err) {
console.error(`checkAppAccountSyncEnable code: code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkAppAccountSyncEnable result: ' + result);
}
});
checkAppAccountSyncEnable(deprecated)
checkAppAccountSyncEnable(name: string): Promise<boolean>
Checks whether data synchronization is enabled for an application 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. Use checkDataSyncEnabled instead.
Required permissions: ohos.permission.DISTRIBUTED_DATASYNC
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means data synchronization is enabled for the application account; the value false means the opposite. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.checkAppAccountSyncEnable('ZhangSan').then((data: boolean) => {
console.info('checkAppAccountSyncEnable, result: ' + data);
}).catch((err: BusinessError) => {
console.error(`checkAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
});
setAccountCredential(deprecated)
setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void
Sets a credential for an application 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. Use setCredential instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| credentialType | string | Yes | Credential type. |
| credential | string | Yes | Credential value. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001', (err: BusinessError) => {
if (err) {
console.error(`setAccountCredential err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAccountCredential successful.');
}
});
setAccountCredential(deprecated)
setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>
Sets a credential for an application 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. Use setCredential instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| credentialType | string | Yes | Credential type. |
| credential | string | Yes | Credential value. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAccountCredential('ZhangSan', 'credentialType001', 'credential001').then(() => {
console.info('setAccountCredential Success');
}).catch((err: BusinessError) => {
console.error(`setAccountCredential err: code is ${err.code}, message is ${err.message}`);
});
setAccountExtraInfo(deprecated)
setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void
Sets additional information for an application 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. Use setCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002', (err: BusinessError) => {
if (err) {
console.error(`setAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAccountExtraInfo successful.');
}
});
setAccountExtraInfo(deprecated)
setAccountExtraInfo(name: string, extraInfo: string): Promise<void>
Sets additional information for an application 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. Use setCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the application account password and token. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAccountExtraInfo('ZhangSan', 'Tk002').then(() => {
console.info('setAccountExtraInfo Success');
}).catch((err: BusinessError) => {
console.error(`setAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
});
setAppAccountSyncEnable(deprecated)
setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void
Sets data synchronization for an application 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. Use setDataSyncEnabled instead.
Required permissions: ohos.permission.DISTRIBUTED_DATASYNC
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| isEnable | boolean | Yes | Whether to enable data synchronization. The value true means that data synchronization is enabled, and false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAppAccountSyncEnable('ZhangSan', true, (err: BusinessError) => {
if (err) {
console.error(`setAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAppAccountSyncEnable successful.');
}
});
setAppAccountSyncEnable(deprecated)
setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>
Sets data synchronization for an application 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. Use setDataSyncEnabled instead.
Required permissions: ohos.permission.DISTRIBUTED_DATASYNC
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| isEnable | boolean | Yes | Whether to enable data synchronization. The value true means that data synchronization is enabled, and false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAppAccountSyncEnable('ZhangSan', true).then(() => {
console.info('setAppAccountSyncEnable Success');
}).catch((err: BusinessError) => {
console.error(`setAppAccountSyncEnable err: code is ${err.code}, message is ${err.message}`);
});
setAssociatedData(deprecated)
setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void
Sets data to be associated with an application 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. Use setCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| key | string | Yes | Key of the associated data. |
| value | string | Yes | Value of the data to set. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001', (err: BusinessError) => {
if (err) {
console.error(`setAssociatedData err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setAssociatedData successful.');
}
});
setAssociatedData(deprecated)
setAssociatedData(name: string, key: string, value: string): Promise<void>
Sets data to be associated with an application 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. Use setCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| key | string | Yes | Key of the associated data. |
| value | string | Yes | Value of the data to set. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setAssociatedData('ZhangSan', 'k001', 'v001').then(() => {
console.info('setAssociatedData Success');
}).catch((err: BusinessError) => {
console.error(`setAssociatedData err: code is ${err.code}, message is ${err.message}`);
});
getAllAccessibleAccounts(deprecated)
getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void
Obtains information about all accessible application 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. Use getAllAccounts instead.
Required permissions: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications)
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<AppAccountInfo>> | Yes | Callback used to return the result. If the operation is successful, err is null and data is a list of accessible application accounts. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAllAccessibleAccounts((err: BusinessError, data: appAccount.AppAccountInfo[])=>{
if (err) {
console.error(`getAllAccessibleAccounts err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAllAccessibleAccounts data: ' + JSON.stringify(data));
}
});
getAllAccessibleAccounts(deprecated)
getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>
Obtains information about all accessible application 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. Use getAllAccounts instead.
Required permissions: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications)
System capability: SystemCapability.Account.AppAccount
Return value
| Type | Description |
|---|---|
| Promise<Array<AppAccountInfo>> | Promise used to return information about all accessible accounts. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAllAccessibleAccounts().then((data: appAccount.AppAccountInfo[]) => {
console.info('getAllAccessibleAccounts: ' + data);
}).catch((err: BusinessError) => {
console.error(`getAllAccessibleAccounts err: code is ${err.code}, message is ${err.message}`);
});
getAllAccounts(deprecated)
getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void
Obtains the application accounts that can be accessed by the invoker based on the application 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. Use getAccountsByOwner instead.
Required permissions: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications)
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| callback | AsyncCallback<Array<AppAccountInfo>> | Yes | Callback used to return information about all accessible application accounts. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle, (err: BusinessError, data: appAccount.AppAccountInfo[])=>{
if (err) {
console.error(`getAllAccounts err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAllAccounts data:' + JSON.stringify(data));
}
});
getAllAccounts(deprecated)
getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>
Obtains the application accounts that can be accessed by the invoker based on the application 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. Use getAccountsByOwner instead.
Required permissions: ohos.permission.GET_ALL_APP_ACCOUNTS (available only for system applications)
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<Array<AppAccountInfo>> | Promise used to return the application accounts that can be accessed by the invoker. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
const selfBundle = 'com.example.actsgetallaaccounts';
appAccountManager.getAllAccounts(selfBundle).then((data: appAccount.AppAccountInfo[]) => {
console.info('getAllAccounts: ' + data);
}).catch((err: BusinessError) => {
console.error(`getAllAccounts err: code is ${err.code}, message is ${err.message}`);
});
getAccountCredential(deprecated)
getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void
Obtains the credential of an application 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. Use getCredential instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| credentialType | string | Yes | Credential type. |
| callback | AsyncCallback<string> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001', (err: BusinessError, result: string) => {
if (err) {
console.error(`getAccountCredential err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAccountCredential result: ' + result);
}
});
getAccountCredential(deprecated)
getAccountCredential(name: string, credentialType: string): Promise<string>
Obtains the credential of an application 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. Use getCredential instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| credentialType | string | Yes | Credential type. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the credential obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAccountCredential('ZhangSan', 'credentialType001').then((data: string) => {
console.info('getAccountCredential, result: ' + data);
}).catch((err: BusinessError) => {
console.error(`getAccountCredential err: code is ${err.code}, message is ${err.message}`);
});
getAccountExtraInfo(deprecated)
getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void
Obtains additional information of an application account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the application 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. Use getCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| callback | AsyncCallback<string> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAccountExtraInfo('ZhangSan', (err: BusinessError, result: string) => {
if (err) {
console.error(`getAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAccountExtraInfo result: ' + result);
}
});
getAccountExtraInfo(deprecated)
getAccountExtraInfo(name: string): Promise<string>
Obtains additional information of an application account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the application 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. Use getCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the additional information obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAccountExtraInfo('ZhangSan').then((data: string) => {
console.info('getAccountExtraInfo, result: ' + data);
}).catch((err: BusinessError) => {
console.error(`getAccountExtraInfo err: code is ${err.code}, message is ${err.message}`);
});
getAssociatedData(deprecated)
getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void
Obtains the associated data of an application account based on the specified key. 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. Use getCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| key | string | Yes | Key of the associated data. |
| callback | AsyncCallback<string> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAssociatedData('ZhangSan', 'k001', (err: BusinessError, result: string) => {
if (err) {
console.error(`getAssociatedData err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAssociatedData result: ' + result);
}
});
getAssociatedData(deprecated)
getAssociatedData(name: string, key: string): Promise<string>
Obtains data associated with an application 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. Use getCustomData instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| key | string | Yes | Key of the associated data. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the data obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAssociatedData('ZhangSan', 'k001').then((data: string) => {
console.info('getAssociatedData: ' + data);
}).catch((err: BusinessError) => {
console.error(`getAssociatedData err: code is ${err.code}, message is ${err.message}`);
});
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. Use on('accountChange') instead.
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 | Application bundle names of the account. |
| callback | Callback<Array<AppAccountInfo>> | Yes | Callback registered to return the list of changed application accounts. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
console.info('receive change data:' + JSON.stringify(data));
}
try {
appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
const err = e as BusinessError;
console.error(`on accountOnOffDemo code is ${err.code}, message is ${err.message}`);
}
off('change')(deprecated)
off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void
Unsubscribes from account information changes.
NOTE
This API is supported since API version 7 and deprecated since API version 9. Use off('accountChange') instead.
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. |
| callback | Callback<Array<AppAccountInfo>> | No | Callback to unregister. By default, no value is passed, which means to unregister all callbacks for the specified event. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
function changeOnCallback(data: appAccount.AppAccountInfo[]): void {
console.info('receive change data: ' + JSON.stringify(data));
appAccountManager.off('change', () => {
console.info('off finish');
})
}
try {
appAccountManager.on('change', ['com.example.actsaccounttest'], changeOnCallback);
} catch (e) {
const err = e as BusinessError;
console.error(`on accountOnOffDemo err: code is ${err.code}, message is ${err.message}`);
}
authenticate(deprecated)
authenticate(name: string, owner: string, authType: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void
Authenticates an application 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. Use auth instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| options | {[key: string]: any} | Yes | Options for the authentication. |
| callback | AuthenticatorCallback | Yes | Authenticator callback used to return the result. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, common } from '@kit.AbilityKit';
@Entry
@Component
struct Index {
context = this.getUIContext().getHostContext() as common.UIAbilityContext; // UIAbilityContext
onResultCallback(code: number, result: Record<string, Object>): void {
console.info('resultCode: ' + code);
console.info('result: ' + JSON.stringify(result));
}
onRequestRedirectedCallback(request: Want): void {
let wantInfo: Want = {
deviceId: '',
bundleName: 'com.example.accountjsdemo',
action: 'ohos.want.action.viewData',
entities: ['entity.system.default'],
}
this.context.startAbility(wantInfo).then(() => {
console.info('startAbility successfully');
}).catch((err: BusinessError) => {
console.error(`startAbility err: code is ${err.code}, message is ${err.message}`);
})
}
aboutToAppear(): void {
appAccountManager.authenticate('LiSi', 'com.example.accountjsdemo', 'getSocialData', {}, {
onResult: this.onResultCallback,
onRequestRedirected: this.onRequestRedirectedCallback
});
}
build() {}
}
getOAuthToken(deprecated)
getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void
Obtains the authorization token of the specified authentication type for an application 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. Use getAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| callback | AsyncCallback<string> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData',
(err: BusinessError, data: string) => {
if (err) {
console.error(`getOAuthToken err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getOAuthToken token: ' + data);
}
});
getOAuthToken(deprecated)
getOAuthToken(name: string, owner: string, authType: string): Promise<string>
Obtains the authorization token of the specified authentication type for an application 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. Use getAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise used to return the authorization token obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData').then((data: string) => {
console.info('getOAuthToken token: ' + data);
}).catch((err: BusinessError) => {
console.error(`getOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
setOAuthToken(deprecated)
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void
Sets an authorization token of the specific authentication type for an application 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. Use setAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx', (err: BusinessError) => {
if (err) {
console.error(`setOAuthToken err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setOAuthToken successful.');
}
});
setOAuthToken(deprecated)
setOAuthToken(name: string, authType: string, token: string): Promise<void>
Sets an authorization token of the specific authentication type for an application 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. Use setAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setOAuthToken('LiSi', 'getSocialData', 'xxxx').then(() => {
console.info('setOAuthToken successfully');
}).catch((err: BusinessError) => {
console.error(`setOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
deleteOAuthToken(deprecated)
deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void
Deletes the authorization token of the specified authentication type for an application 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. Use deleteAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx',
(err: BusinessError) => {
if (err) {
console.error(`deleteOAuthToken err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('deleteOAuthToken successful.');
}
});
deleteOAuthToken(deprecated)
deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>
Deletes the authorization token of the specified authentication type for an application 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. Use deleteAuthToken instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| authType | string | Yes | Authentication type. |
| token | string | Yes | Authorization token. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.deleteOAuthToken('LiSi', 'com.example.accountjsdemo', 'getSocialData', 'xxxxx').then(() => {
console.info('deleteOAuthToken successfully');
}).catch((err: BusinessError) => {
console.error(`deleteOAuthToken err: code is ${err.code}, message is ${err.message}`);
});
setOAuthTokenVisibility(deprecated)
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void
Sets the visibility of an authorization token to an application. 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. Use setAuthTokenVisibility instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value true means the authorization token is visible to the application; the value false means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, err is null. Otherwise, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true,
(err: BusinessError) => {
if (err) {
console.error(`setOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('setOAuthTokenVisibility successful.');
}
});
setOAuthTokenVisibility(deprecated)
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>
Sets the visibility of an authorization token to an application. This API uses a promise to return the result.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use setAuthTokenVisibility instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| isVisible | boolean | Yes | Whether the authorization token is visible to the application. The value true means the authorization token is visible to the application; the value false means the opposite. |
Return value
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.setOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo', true).then(() => {
console.info('setOAuthTokenVisibility successfully');
}).catch((err: BusinessError) => {
console.error(`setOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
});
checkOAuthTokenVisibility(deprecated)
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 application. 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. Use checkAuthTokenVisibility instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the operation is successful, err is null and data can be true (the authorization token is visible to the application) or false (the authorization token is not visible to the application). If the operation fails, err is an error object. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo',
(err: BusinessError, data: boolean) => {
if (err) {
console.error(`checkOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('checkOAuthTokenVisibility isVisible: ' + data);
}
});
checkOAuthTokenVisibility(deprecated)
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>
Checks the visibility of an authorization token of the specified authentication type to an application. This API uses a promise to return the result.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use checkAuthTokenVisibility instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| bundleName | string | Yes | Bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the result. The value true means the authorization token is visible to the application; the value false means the opposite. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.checkOAuthTokenVisibility('LiSi', 'getSocialData', 'com.example.accountjsdemo').then((
data: boolean) => {
console.info('checkOAuthTokenVisibility isVisible: ' + data);
}).catch((err: BusinessError) => {
console.error(`checkOAuthTokenVisibility err: code is ${err.code}, message is ${err.message}`);
});
getAllOAuthTokens(deprecated)
getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void
Obtains all tokens visible to the invoker for an application 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. Use getAllAuthTokens instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| callback | AsyncCallback<Array<OAuthTokenInfo>> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo',
(err: BusinessError, data: appAccount.OAuthTokenInfo[]) => {
if (err) {
console.error(`getAllOAuthTokens err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAllOAuthTokens data: ' + JSON.stringify(data));
}
});
getAllOAuthTokens(deprecated)
getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>>
Obtains all tokens visible to the invoker for an application 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. Use getAllAuthTokens instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<Array< OAuthTokenInfo>> | Promise used to return the tokens obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAllOAuthTokens('LiSi', 'com.example.accountjsdemo').then((
data: appAccount.OAuthTokenInfo[]) => {
console.info('getAllOAuthTokens data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error(`getAllOAuthTokens err: code is ${err.code}, message is ${err.message}`);
});
getOAuthList(deprecated)
getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void
Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility. 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. Use getAuthList instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
| callback | AsyncCallback<Array<string>> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getOAuthList('LiSi', 'getSocialData', (err: BusinessError, data: string[]) => {
if (err) {
console.error(`getOAuthList err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getOAuthList data: ' + JSON.stringify(data));
}
});
getOAuthList(deprecated)
getOAuthList(name: string, authType: string): Promise<Array<string>>
Obtains the authorization list of the specified authentication type for an application account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility. This API uses a promise to return the result.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use getAuthList instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application account. |
| authType | string | Yes | Authentication type. |
Return value
| Type | Description |
|---|---|
| Promise<Array<string>> | Promise used to return a list of authorized bundles. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getOAuthList('LiSi', 'getSocialData').then((data: string[]) => {
console.info('getOAuthList data: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error(`getOAuthList err: code is ${err.code}, message is ${err.message}`);
});
getAuthenticatorCallback(deprecated)
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.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use getAuthCallback instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| sessionId | string | Yes | ID of the authentication session. |
| callback | AsyncCallback<AuthenticatorCallback> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
appAccountManager.getAuthenticatorCallback(sessionId,
(err: BusinessError, callback: appAccount.AuthenticatorCallback) => {
if (err.code != appAccount.ResultCode.SUCCESS) {
console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
return;
}
callback.onResult(appAccount.ResultCode.SUCCESS, {
name: 'LiSi',
owner: 'com.example.accountjsdemo',
authType: 'getSocialData',
token: 'xxxxxx'
});
});
}
}
getAuthenticatorCallback(deprecated)
getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback>
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. Use getAuthCallback instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| sessionId | string | Yes | ID of the authentication session. |
Return value
| Type | Description |
|---|---|
| Promise<AuthenticatorCallback> | Promise used to return the authenticator callback obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
import { Want, UIAbility, AbilityConstant } from '@kit.AbilityKit';
export default class EntryAbility extends UIAbility {
onCreate(want: Want, param: AbilityConstant.LaunchParam) { // Ability lifecycle function.
let sessionId: string = want.parameters![appAccount.Constants.KEY_SESSION_ID] as string;
appAccountManager.getAuthenticatorCallback(sessionId).then((
callback: appAccount.AuthenticatorCallback) => {
callback.onResult(appAccount.ResultCode.SUCCESS, {
name: 'LiSi',
owner: 'com.example.accountjsdemo',
authType: 'getSocialData',
token: 'xxxxxx'
});
}).catch((err: BusinessError) => {
console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
});
}
}
getAuthenticatorInfo(deprecated)
getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void
Obtains the authenticator information of an application. 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. Use queryAuthenticatorInfo instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
| callback | AsyncCallback<AuthenticatorInfo> | Yes | Callback used 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
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo',
(err: BusinessError, data: appAccount.AuthenticatorInfo) => {
if (err) {
console.error(`getAuthenticatorInfo err: code is ${err.code}, message is ${err.message}`);
} else {
console.info('getAuthenticatorInfo data: ' + JSON.stringify(data));
}
});
getAuthenticatorInfo(deprecated)
getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>
Obtains the authenticator information of an application. This API uses a promise to return the result.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use queryAuthenticatorInfo instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| owner | string | Yes | Owner of the application account. The value is the bundle name of the application. |
Return value
| Type | Description |
|---|---|
| Promise<AuthenticatorInfo> | Promise used to return the authenticator information obtained. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
appAccountManager.getAuthenticatorInfo('com.example.accountjsdemo').then((
data: appAccount.AuthenticatorInfo) => {
console.info('getAuthenticatorInfo: ' + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error(`getAuthenticatorInfo err: code is ${err.code}, message is ${err.message}`);
});
AppAccountInfo
Defines application account information.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| owner | string | No | No | Owner of the application account. The value is the bundle name of the application. |
| name | string | No | No | Name of the application account. |
AuthTokenInfo9+
Defines authorization token information.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| authType | string | No | No | Authentication type. |
| token | string | No | No | Value of the authorization token. |
| account | AppAccountInfo | No | Yes | Information about the account to which the token belongs. By default, no value is passed in. |
OAuthTokenInfo(deprecated)
Defines authorization token information.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use AuthTokenInfo instead.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| authType | string | No | No | Authentication type. |
| token | string | No | No | Value of the authorization token. |
AuthenticatorInfo8+
Defines OAuth authenticator information.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| owner | string | No | No | Owner of the authenticator. The value is the bundle name of the application. |
| iconId | number | No | No | ID of the authenticator icon. |
| labelId | number | No | No | ID of the authenticator label. |
AuthResult9+
Defines the authentication result.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| account | AppAccountInfo | No | Yes | Information about the account to which the token belongs. By default, no value is passed in. |
| tokenInfo | AuthTokenInfo | No | Yes | Token information. By default, no value is passed in. |
CreateAccountOptions9+
Defines the options for creating an application account.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| customData | Record<string, string> | No | Yes | Custom data. By default, no value is passed in. |
CreateAccountImplicitlyOptions9+
Defines the options for implicitly creating an application account.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| requiredLabels | Array<string> | No | Yes | Required labels. By default, no value is passed in. |
| authType | string | No | Yes | Authentication type. By default, no value is passed in. |
| parameters | Record<string, Object> | No | Yes | Custom parameter object. By default, no value is passed in. |
SelectAccountsOptions9+
Defines the options for selecting accounts.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| allowedAccounts | Array<AppAccountInfo> | No | Yes | Array of allowed accounts. By default, no value is passed in. |
| allowedOwners | Array<string> | No | Yes | Array of the owners of the allowed accounts. By default, no value is passed in. |
| requiredLabels | Array<string> | No | Yes | Labels of the authenticator. By default, no value is passed in. |
VerifyCredentialOptions9+
Represents the options for verifying the user credential.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| credentialType | string | No | Yes | Credential type. By default, no value is passed in. |
| credential | string | No | Yes | Credential value. By default, no value is passed in. |
| parameters | Record<string, Object> | No | Yes | Custom parameter object. By default, no value is passed in. |
SetPropertiesOptions9+
Represents the options for setting authenticator properties.
System capability: SystemCapability.Account.AppAccount
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| properties | Record<string, Object> | No | Yes | Property object. By default, no value is passed in. |
| parameters | Record<string, Object> | No | Yes | Custom parameter object. By default, no value is passed in. |
Constants8+
Enumerates the constants.
System capability: SystemCapability.Account.AppAccount
| Name | Value | Description |
|---|---|---|
| ACTION_ADD_ACCOUNT_IMPLICITLY(deprecated) | 'addAccountImplicitly' | Operation of adding an account implicitly. Note: This API is supported since API version 8 and deprecated since API version 9. Use ACTION_CREATE_ACCOUNT_IMPLICITLY instead. |
| ACTION_AUTHENTICATE(deprecated) | 'authenticate' | Authentication operation. Note: This API is supported since API version 8 and deprecated since API version 9. Use ACTION_AUTH instead. |
| 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 application account. |
| KEY_OWNER | 'owner' | Bundle name of the application account owner. |
| 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. |
ResultCode(deprecated)
Enumerates the result codes.
NOTE
This API is supported since API version 8 and deprecated since API version 9. For details, see Account Management Error Codes.
System capability: SystemCapability.Account.AppAccount
| Name | Value | Description |
|---|---|---|
| SUCCESS | 0 | The operation is successful. |
| ERROR_ACCOUNT_NOT_EXIST | 10001 | The application 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 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. |
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 | No | Authentication result. By default, no value is passed, which means the authentication result is not received. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
let result: appAccount.AuthResult = {
account: {
name: 'Lisi',
owner: 'com.example.accountjsdemo',
},
tokenInfo: {
token: 'xxxxxx',
authType: 'getSocialData'
}
};
callback.onResult(appAccount.ResultCode.SUCCESS, result);
}).catch((err: BusinessError) => {
console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
});
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
import { Want } from '@kit.AbilityKit';
class MyAuthenticator extends appAccount.Authenticator {
createAccountImplicitly(
options: appAccount.CreateAccountImplicitlyOptions, callback: appAccount.AuthCallback) {
let want: Want = {
bundleName: 'com.example.accountjsdemo',
abilityName: 'com.example.accountjsdemo.LoginAbility',
};
callback.onRequestRedirected(want);
}
auth(name: string, authType: string,
options: Record<string, Object>, callback: appAccount.AuthCallback) {
let result: appAccount.AuthResult = {
account: {
name: 'Lisi',
owner: 'com.example.accountjsdemo',
},
tokenInfo: {
token: 'xxxxxx',
authType: 'getSocialData'
}
};
callback.onResult(appAccount.ResultCode.SUCCESS, result);
}
}
onRequestContinued9+
onRequestContinued?: () => void
Called to continue to process the request.
System capability: SystemCapability.Account.AppAccount
Example
import { BusinessError } from '@kit.BasicServicesKit';
let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthCallback(sessionId).then((callback: appAccount.AuthCallback) => {
if (callback.onRequestContinued != undefined) {
callback.onRequestContinued();
}
}).catch((err: BusinessError) => {
console.error(`getAuthCallback err: code is ${err.code}, message is ${err.message}`);
});
AuthenticatorCallback(deprecated)
Provides OAuth authenticator callbacks.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use AuthCallback instead.
onResult(deprecated)
onResult: (code: number, result: {[key: string]: any;}) => void
Called to return the result of an authentication request.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use onResult instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| code | number | Yes | Authentication result code. |
| result | {[key: string]: any} | Yes | Authentication result. |
Example
import { BusinessError } from '@kit.BasicServicesKit';
let appAccountManager: appAccount.AppAccountManager = appAccount.createAppAccountManager();
let sessionId = '1234';
appAccountManager.getAuthenticatorCallback(sessionId).then((callback: appAccount.AuthenticatorCallback) => {
callback.onResult(appAccount.ResultCode.SUCCESS, {
name: 'LiSi',
owner: 'com.example.accountjsdemo',
authType: 'getSocialData',
token: 'xxxxxx'
});
}).catch((err: BusinessError) => {
console.error(`getAuthenticatorCallback err: code is ${err.code}, message is ${err.message}`);
});
onRequestRedirected(deprecated)
onRequestRedirected: (request: Want) => void
Called to redirect a request.
NOTE
This API is supported since API version 8 and deprecated since API version 9. Use onRequestRedirected instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| request | Want | Yes | Request to be redirected. |
Example
import { Want } from '@kit.AbilityKit';
class MyAuthenticator extends appAccount.Authenticator {
addAccountImplicitly(authType: string, callerBundleName: string,
options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) {
let want: Want = {
bundleName: 'com.example.accountjsdemo',
abilityName: 'com.example.accountjsdemo.LoginAbility',
};
callback.onRequestRedirected(want);
}
authenticate(name: string, authType: string, callerBundleName: string,
options: Record<string, Object>, callback: appAccount.AuthenticatorCallback) {
callback.onResult(appAccount.ResultCode.SUCCESS, {
name: name,
authType: authType,
token: 'xxxxxx'
});
}
}
Authenticator8+
Provides APIs to operate the authenticator.
createAccountImplicitly9+
createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void
Creates an application 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 | Yes | Options for implicitly creating the account. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
addAccountImplicitly(deprecated)
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void
Adds an application 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. Use createAccountImplicitly instead.
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 | Yes | Authenticator callback used to return the result. |
auth9+
auth(name: string, authType: string, options: Record<string, Object>, callback: AuthCallback): void
Authenticates an application 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 application account. |
| authType | string | Yes | Authentication type. |
| options | Record<string, Object> | Yes | Options for the authentication. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
authenticate(deprecated)
authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any;}, callback: AuthenticatorCallback): void
Authenticates an application account to obtain the OAuth 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. Use auth instead.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| name | string | Yes | Name of the application 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 | Yes | Authenticator callback used to return the result. |
verifyCredential9+
verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void
Verifies the credential of an application 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 application account. |
| options | VerifyCredentialOptions | Yes | Options for credential verification. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Example
This API must be used together with the getRemoteObject API. For details, see the example of the getRemoteObject API.
setProperties9+
setProperties(options: SetPropertiesOptions, callback: AuthCallback): void
Sets the authenticator properties. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.Account.AppAccount
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| options | SetPropertiesOptions | Yes | Authenticator properties to set. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Example
This API must be used together with the getRemoteObject API. For details, see the example of the getRemoteObject API.
checkAccountLabels9+
checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): 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 application account. |
| labels | Array<string> | Yes | Labels to check. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Example
This API must be used together with the getRemoteObject API. For details, see the example of the getRemoteObject API.
checkAccountRemovable9+
checkAccountRemovable(name: string, callback: AuthCallback): void
Checks whether an application 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 application account. |
| callback | AuthCallback | Yes | Authenticator callback used to return the result. |
Example
This API must be used together with the getRemoteObject API. For details, see the example of the getRemoteObject API.
getRemoteObject9+
getRemoteObject(): rpc.RemoteObject
Obtains the remote object of an authenticator. This API cannot be overloaded.
System capability: SystemCapability.Account.AppAccount
Return value
| Type | Description |
|---|---|
| rpc.RemoteObject | Remote object of the authenticator, which is used for inter-process communication. |
Example
This API must be used together with the getRemoteObject API. For details, see the example of the getRemoteObject API.
Example
import { rpc } from '@kit.IPCKit';
import { Want } from '@kit.AbilityKit';
class MyAuthenticator extends appAccount.Authenticator {
verifyCredential(name: string,
options: appAccount.VerifyCredentialOptions, callback: appAccount.AuthCallback) {
let want: Want = {
bundleName: 'com.example.accountjsdemo',
abilityName: 'com.example.accountjsdemo.VerifyAbility',
parameters: {
name: name
}
};
callback.onRequestRedirected(want);
}
setProperties(options: appAccount.SetPropertiesOptions, callback: appAccount.AuthCallback) {
let want: Want = {
bundleName: 'com.example.accountjsdemo',
abilityName: 'com.example.accountjsdemo.SetPropertiesAbility',
parameters: {
options: options
}
};
callback.onRequestRedirected(want);
}
checkAccountLabels(name: string, labels: string[], callback: appAccount.AuthCallback) {
callback.onResult(0);
}
checkAccountRemovable(name: string, callback: appAccount.AuthCallback) {
callback.onResult(0);
}
}
export default {
onConnect(want: Want): rpc.RemoteObject { // serviceAbility lifecycle function, which needs to be placed in serviceAbility.
let authenticator = new MyAuthenticator();
return authenticator.getRemoteObject();
}
}