js-apis-appAccount.md 89.6 KB
Newer Older
A
Annie_wang 已提交
1 2
#  	App Account Management

A
Annie_wang 已提交
3
The **appAccount** module provides APIs for app account management. You can use the APIs to add, delete, query, modify, and authorize app accounts, write data to disks, and synchronize data.
A
annie_wangli 已提交
4

5
> **NOTE**<br>
A
annie_wangli 已提交
6 7 8 9 10
> 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

Z
zhangalong 已提交
11
```js
A
annie_wangli 已提交
12 13 14 15 16 17
import account_appAccount from '@ohos.account.appAccount';
```


## account_appAccount.createAppAccountManager

A
annie_wangli 已提交
18
createAppAccountManager(): AppAccountManager
A
annie_wangli 已提交
19 20 21

Creates an **AppAccountManager** instance.

A
annie_wangli 已提交
22
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
23

A
Annie_wang 已提交
24
**Return value**
A
Annie_wang 已提交
25 26 27 28

| Type               | Description          |
| ----------------- | ------------ |
| AppAccountManager | **AppAccountManager** instance created.|
A
annie_wangli 已提交
29 30

**Example**
Z
zhangalong 已提交
31
  ```js
A
Annie_wang 已提交
32
  const appAccountManager = account_appAccount.createAppAccountManager();
A
annie_wangli 已提交
33 34 35 36
  ```

## AppAccountManager

A
annie_wangli 已提交
37
Provides methods to manage app accounts.
A
annie_wangli 已提交
38 39 40

### addAccount

A
annie_wangli 已提交
41
addAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
42

A
Annie_wang 已提交
43
Adds an app account to the **AppAccountManager** service. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
44

A
annie_wangli 已提交
45
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
46

A
annie_wangli 已提交
47
**Parameters**
A
annie_wangli 已提交
48

A
Annie_wang 已提交
49 50 51 52
| Name     | Type                       | Mandatory  | Description                  |
| -------- | ------------------------- | ---- | -------------------- |
| name     | string                    | Yes   | Name of the app account to add.         |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is added.|
A
annie_wangli 已提交
53

A
annie_wangli 已提交
54
**Example**
A
annie_wangli 已提交
55

Z
zhangalong 已提交
56
  ```js
A
annie_wangli 已提交
57 58 59 60 61 62 63 64
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("WangWu", (err) => { 
      console.log("addAccount err: " + JSON.stringify(err));
  });
  ```

### addAccount

A
annie_wangli 已提交
65
addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
66

A
Annie_wang 已提交
67
Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
68

A
annie_wangli 已提交
69
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
70

A
annie_wangli 已提交
71
**Parameters**
A
annie_wangli 已提交
72

A
Annie_wang 已提交
73 74 75 76 77
| Name      | Type                       | Mandatory  | Description                                      |
| --------- | ------------------------- | ---- | ---------------------------------------- |
| name      | string                    | Yes   | Name of the app account to add.                             |
| extraInfo | string                    | Yes   | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.|
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account name and additional information are added.            |
A
annie_wangli 已提交
78

A
annie_wangli 已提交
79
**Example**
A
annie_wangli 已提交
80

Z
zhangalong 已提交
81
  ```js
A
annie_wangli 已提交
82 83 84 85 86 87 88 89 90 91
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("LiSi", "token101", (err) => { 
      console.log("addAccount err: " + JSON.stringify(err));
  });
  ```



### addAccount

A
Annie_wang 已提交
92
addAccount(name: string, extraInfo: string): Promise&lt;void&gt;
A
annie_wangli 已提交
93

A
Annie_wang 已提交
94
Adds an app account name and additional information (information that can be converted into the string type, such as token) to the **AppAccountManager** service. This API uses a promise to return the result.
A
annie_wangli 已提交
95

A
annie_wangli 已提交
96
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
97

A
annie_wangli 已提交
98
**Parameters**
A
annie_wangli 已提交
99

A
Annie_wang 已提交
100 101 102 103
| Name      | Type    | Mandatory  | Description                                      |
| --------- | ------ | ---- | ---------------------------------------- |
| name      | string | Yes   | Name of the app account to add.                             |
| extraInfo | string | Yes   | Additional information to add. The additional information cannot contain sensitive information, such as the app account password.|
A
annie_wangli 已提交
104

A
Annie_wang 已提交
105
**Return value**
A
annie_wangli 已提交
106

A
Annie_wang 已提交
107 108 109
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
110

A
annie_wangli 已提交
111
**Example**
A
annie_wangli 已提交
112

Z
zhangalong 已提交
113
  ```js
A
annie_wangli 已提交
114 115 116 117 118 119 120 121
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccount("LiSi", "token101").then(()=> { 
      console.log('addAccount Success');
  }).catch((err) => {
      console.log("addAccount err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
122 123
### addAccountImplicitly<sup>8+</sup>

A
annie_wangli 已提交
124
addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
125

A
Annie_wang 已提交
126
Implicitly adds an app account based on the specified account owner, authentication type, and options. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
127

A
annie_wangli 已提交
128
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
129

A
annie_wangli 已提交
130
**Parameters**
A
annie_wangli 已提交
131

A
Annie_wang 已提交
132 133 134 135 136
| Name     | Type                   | Mandatory  | Description                     |
| -------- | --------------------- | ---- | ----------------------- |
| owner    | string                | Yes   | Owner of the app account to add. The value is the bundle name of the app.         |
| authType | string                | Yes   | Authentication type of the app account to add. The authentication type is customized. |
| options  | {[key: string]: any}  | Yes   | Authentication options, which can be set as required.|
A
Annie_wang 已提交
137
| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the authentication result.        |
A
annie_wangli 已提交
138

A
annie_wangli 已提交
139
**Example**
A
annie_wangli 已提交
140

Z
zhangalong 已提交
141
  ```js
A
annie_wangli 已提交
142
  import featureAbility from '@ohos.ability.featureAbility';
A
annie_wangli 已提交
143

A
annie_wangli 已提交
144 145 146 147
  function onResultCallback(code, result) {
      console.log("resultCode: "  + code);
      console.log("result: "  + JSON.stringify(result));
  }
A
annie_wangli 已提交
148

A
annie_wangli 已提交
149 150 151 152 153 154
  function onRequestRedirectedCallback(request) {
      let abilityStartSetting = {want: request};
      featureAbility.startAbility(abilityStartSetting, (err)=>{
          console.log("startAbility err: " + JSON.stringify(err));
      });
  }
A
annie_wangli 已提交
155

A
annie_wangli 已提交
156 157 158 159 160 161 162
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.addAccountImplicitly("LiSi", "readAge", {}, {
      onResult: onResultCallback,
      onRequestRedirected: onRequestRedirectedCallback
  });
  ```

A
annie_wangli 已提交
163 164
### deleteAccount

A
annie_wangli 已提交
165
deleteAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
166

A
Annie_wang 已提交
167
Deletes an app account from the **AppAccountManager** service. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
168

A
annie_wangli 已提交
169
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
170

A
annie_wangli 已提交
171
**Parameters**
A
annie_wangli 已提交
172

A
Annie_wang 已提交
173 174 175 176
| Name     | Type                       | Mandatory  | Description              |
| -------- | ------------------------- | ---- | ---------------- |
| name     | string                    | Yes   | Name of the app account to delete.     |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is deleted.|
A
annie_wangli 已提交
177 178

**Example**
A
annie_wangli 已提交
179

Z
zhangalong 已提交
180
  ```js
A
annie_wangli 已提交
181 182 183 184 185 186 187 188
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccount("ZhaoLiu", (err) => { 
      console.log("deleteAccount err: " + JSON.stringify(err));
   });
  ```

### deleteAccount

A
annie_wangli 已提交
189
deleteAccount(name: string): Promise&lt;void&gt;
A
annie_wangli 已提交
190

A
Annie_wang 已提交
191
Deletes an app account from the **AppAccountManager** service. This API uses a promise to return the result.
A
annie_wangli 已提交
192

A
annie_wangli 已提交
193 194 195
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
196

A
Annie_wang 已提交
197 198 199
| Name | Type    | Mandatory  | Description         |
| ---- | ------ | ---- | ----------- |
| name | string | Yes   | Name of the app account to delete.|
A
annie_wangli 已提交
200

A
Annie_wang 已提交
201
**Return value**
A
annie_wangli 已提交
202

A
Annie_wang 已提交
203 204 205
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
206

A
annie_wangli 已提交
207
**Example**
A
annie_wangli 已提交
208

Z
zhangalong 已提交
209
  ```js
A
annie_wangli 已提交
210 211 212 213 214 215 216 217 218 219
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccount("ZhaoLiu").then(() => { 
        console.log('deleteAccount Success');
   }).catch((err) => {
      console.log("deleteAccount err: "  + JSON.stringify(err));
  });
  ```

### disableAppAccess

A
annie_wangli 已提交
220
disableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
221

A
Annie_wang 已提交
222
Disables an app account from accessing an app with the given bundle name. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
223

A
annie_wangli 已提交
224
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
225

A
annie_wangli 已提交
226
**Parameters**
A
annie_wangli 已提交
227

A
Annie_wang 已提交
228 229 230 231 232
| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| bundleName | string                    | Yes   | Bundle name of the app.                        |
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
233 234

**Example**
A
annie_wangli 已提交
235

Z
zhangalong 已提交
236
  ```js
A
annie_wangli 已提交
237
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
238
  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { 
A
annie_wangli 已提交
239 240 241 242 243 244
      console.log("disableAppAccess err: " + JSON.stringify(err));
  });
  ```

### disableAppAccess

A
annie_wangli 已提交
245
disableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
A
annie_wangli 已提交
246

A
Annie_wang 已提交
247
Disables an app account from accessing an app with the given bundle name. This API uses a promise to return the result.
A
annie_wangli 已提交
248

A
annie_wangli 已提交
249 250 251
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
252

A
Annie_wang 已提交
253 254 255 256
| Name       | Type    | Mandatory  | Description              |
| ---------- | ------ | ---- | ---------------- |
| name       | string | Yes   | Name of the target app account.|
| bundleName | string | Yes   | Bundle name of the app.       |
A
annie_wangli 已提交
257

A
Annie_wang 已提交
258
**Return value**
A
annie_wangli 已提交
259

A
Annie_wang 已提交
260 261 262
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
263

A
annie_wangli 已提交
264
**Example**
A
annie_wangli 已提交
265

Z
zhangalong 已提交
266
  ```js
A
annie_wangli 已提交
267
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
268
  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { 
A
annie_wangli 已提交
269 270 271 272 273 274 275 276
      console.log('disableAppAccess Success');
  }).catch((err) => {
      console.log("disableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### enableAppAccess

A
annie_wangli 已提交
277
enableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
278

A
Annie_wang 已提交
279
Enables an app account to access an app with the given bundle name. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
280

A
annie_wangli 已提交
281 282 283
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
284

A
Annie_wang 已提交
285 286 287
| Name       | Type                       | Mandatory  | Description                               |
| ---------- | ------------------------- | ---- | --------------------------------- |
| name       | string                    | Yes   | Name of the target app account.                          |
A
Annie_wang 已提交
288
| bundleName | string                    | Yes   | Bundle name of the app.                        |
A
Annie_wang 已提交
289
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
290

A
annie_wangli 已提交
291
**Example**
A
annie_wangli 已提交
292

Z
zhangalong 已提交
293
  ```js
A
annie_wangli 已提交
294
  const appAccountManager = account_appAccount.createAppAccountManager();
Z
zengyawen 已提交
295
  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => { 
A
annie_wangli 已提交
296 297 298 299 300 301
      console.log("enableAppAccess: " + JSON.stringify(err));
   });
  ```

### enableAppAccess

A
annie_wangli 已提交
302
enableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
A
annie_wangli 已提交
303

A
Annie_wang 已提交
304
Enables an app account to access an app with the given bundle name. This API uses a promise to return the result.
A
annie_wangli 已提交
305

A
annie_wangli 已提交
306
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
307

A
annie_wangli 已提交
308
**Parameters**
A
annie_wangli 已提交
309

A
Annie_wang 已提交
310 311 312
| Name       | Type    | Mandatory  | Description       |
| ---------- | ------ | ---- | --------- |
| name       | string | Yes   | Name of the target app account.  |
A
Annie_wang 已提交
313
| bundleName | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
314

A
Annie_wang 已提交
315
**Return value**
A
annie_wangli 已提交
316

A
Annie_wang 已提交
317 318 319
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
320 321

**Example**
A
annie_wangli 已提交
322

Z
zhangalong 已提交
323
  ```js
Z
zengyawen 已提交
324
  app_account_instance.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => { 
A
annie_wangli 已提交
325 326 327 328 329 330 331 332
       console.log('enableAppAccess Success');
  }).catch((err) => {
      console.log("enableAppAccess err: "  + JSON.stringify(err));
  });
  ```

### checkAppAccountSyncEnable

A
annie_wangli 已提交
333
checkAppAccountSyncEnable(name: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
334

A
Annie_wang 已提交
335
Checks whether an app account allows app data synchronization. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
336

A
annie_wangli 已提交
337 338 339
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
340

A
annie_wangli 已提交
341
**Parameters**
A
annie_wangli 已提交
342

A
Annie_wang 已提交
343 344 345 346
| Name     | Type                          | Mandatory  | Description                   |
| -------- | ---------------------------- | ---- | --------------------- |
| name     | string                       | Yes   | Name of the target app account.              |
| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
347

A
annie_wangli 已提交
348
**Example**
A
annie_wangli 已提交
349

Z
zhangalong 已提交
350
  ```js
A
annie_wangli 已提交
351 352 353 354 355 356 357 358 359
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { 
      console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
      console.log('checkAppAccountSyncEnable result: ' + result);
  });
  ```

### checkAppAccountSyncEnable

A
annie_wangli 已提交
360
checkAppAccountSyncEnable(name: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
361

A
Annie_wang 已提交
362
Checks whether an app account allows app data synchronization. This API uses a promise to return the result.
A
annie_wangli 已提交
363

A
annie_wangli 已提交
364
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)
A
annie_wangli 已提交
365

A
annie_wangli 已提交
366
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
367

A
annie_wangli 已提交
368
**Parameters**
A
annie_wangli 已提交
369

A
Annie_wang 已提交
370 371 372
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|
A
annie_wangli 已提交
373

A
Annie_wang 已提交
374
**Return value**
A
annie_wangli 已提交
375

A
Annie_wang 已提交
376 377 378
| Type                    | Description                   |
| :--------------------- | :-------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
A
annie_wangli 已提交
379 380

**Example**
A
annie_wangli 已提交
381

Z
zhangalong 已提交
382
  ```js
A
annie_wangli 已提交
383 384 385 386 387 388 389 390 391 392
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { 
      console.log('checkAppAccountSyncEnable, result: ' + data);
  }).catch((err) => {
      console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAccountCredential

A
Annie_wang 已提交
393
setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
394

A
Annie_wang 已提交
395
Sets a credential for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
396

A
annie_wangli 已提交
397 398 399
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
400

A
Annie_wang 已提交
401 402 403 404 405 406
| Name           | Type                       | Mandatory  | Description           |
| -------------- | ------------------------- | ---- | ------------- |
| name           | string                    | Yes   | Name of the target app account.    |
| credentialType | string                    | Yes   | Type of the credential to set.    |
| credential     | string                    | Yes   | Credential to set.      |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
407

A
annie_wangli 已提交
408
**Example**
A
annie_wangli 已提交
409

Z
zhangalong 已提交
410
  ```js
A
annie_wangli 已提交
411 412 413 414 415 416 417 418
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { 
      console.log("setAccountCredential err: " + JSON.stringify(err));
  });
  ```

### setAccountCredential

A
annie_wangli 已提交
419
setAccountCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;
A
annie_wangli 已提交
420

A
Annie_wang 已提交
421
Sets a credential for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
422

A
annie_wangli 已提交
423
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
424

A
annie_wangli 已提交
425
**Parameters**
A
annie_wangli 已提交
426

A
Annie_wang 已提交
427 428 429 430 431
| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.  |
| credentialType | string | Yes   | Type of the credential to set.|
| credential     | string | Yes   | Credential to set.   |
A
annie_wangli 已提交
432

A
Annie_wang 已提交
433
**Return value**
A
annie_wangli 已提交
434

A
Annie_wang 已提交
435 436 437
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
438 439

**Example**
A
annie_wangli 已提交
440

Z
zhangalong 已提交
441
  ```js
A
annie_wangli 已提交
442 443 444 445 446 447 448 449 450 451
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { 
      console.log('setAccountCredential Success');
  }).catch((err) => {
      console.log("setAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo

A
annie_wangli 已提交
452
setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
453

A
Annie_wang 已提交
454
Sets additional information for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
455

A
annie_wangli 已提交
456 457 458
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
459

A
Annie_wang 已提交
460 461 462 463 464
| Name      | Type                       | Mandatory  | Description             |
| --------- | ------------------------- | ---- | --------------- |
| name      | string                    | Yes   | Name of the target app account.        |
| extraInfo | string                    | Yes   | Additional information to set.      |
| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
A
annie_wangli 已提交
465

A
annie_wangli 已提交
466
**Example**
A
annie_wangli 已提交
467

Z
zhangalong 已提交
468
  ```js
A
annie_wangli 已提交
469 470 471 472 473 474 475 476
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { 
      console.log("setAccountExtraInfo err: " + JSON.stringify(err));
  });
  ```

### setAccountExtraInfo

A
annie_wangli 已提交
477
setAccountExtraInfo(name: string, extraInfo: string): Promise&lt;void&gt;
A
annie_wangli 已提交
478

A
Annie_wang 已提交
479
Sets additional information for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
480

A
annie_wangli 已提交
481
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
482

A
annie_wangli 已提交
483
**Parameters**
A
annie_wangli 已提交
484

A
Annie_wang 已提交
485 486 487 488
| Name      | Type    | Mandatory  | Description       |
| --------- | ------ | ---- | --------- |
| name      | string | Yes   | Name of the target app account.  |
| extraInfo | string | Yes   | Additional information to set.|
A
annie_wangli 已提交
489

A
Annie_wang 已提交
490
**Return value**
A
annie_wangli 已提交
491

A
Annie_wang 已提交
492 493 494
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
495 496

**Example**
A
annie_wangli 已提交
497

Z
zhangalong 已提交
498
  ```js
A
annie_wangli 已提交
499 500 501 502 503 504 505 506 507 508
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { 
      console.log('setAccountExtraInfo Success');
  }).catch((err) => {
      console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable

A
annie_wangli 已提交
509
setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
510

A
Annie_wang 已提交
511
Sets whether to enable app data synchronization for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
512

A
annie_wangli 已提交
513 514 515
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
516

A
annie_wangli 已提交
517
**Parameters**
A
annie_wangli 已提交
518

A
Annie_wang 已提交
519 520 521 522 523
| Name     | Type                       | Mandatory  | Description                       |
| -------- | ------------------------- | ---- | ------------------------- |
| name     | string                    | Yes   | Name of the target app account.                  |
| isEnable | boolean                   | Yes   | Whether to enable app data synchronization.              |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when app data synchronization is enabled or disabled for the app account.|
A
annie_wangli 已提交
524

A
annie_wangli 已提交
525
**Example**
A
annie_wangli 已提交
526

Z
zhangalong 已提交
527
  ```js
A
annie_wangli 已提交
528 529 530 531 532 533 534 535
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { 
      console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
  });
  ```

### setAppAccountSyncEnable

A
annie_wangli 已提交
536
setAppAccountSyncEnable(name: string, isEnable: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
537

A
Annie_wang 已提交
538
Sets whether to enable app data synchronization for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
539

A
annie_wangli 已提交
540 541 542
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC (available only to system applications)

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
543

A
annie_wangli 已提交
544
**Parameters**
A
annie_wangli 已提交
545

A
Annie_wang 已提交
546 547 548 549
| Name     | Type     | Mandatory  | Description         |
| -------- | ------- | ---- | ----------- |
| name     | string  | Yes   | Name of the target app account.    |
| isEnable | boolean | Yes   | Whether to enable app data synchronization.|
A
annie_wangli 已提交
550

A
Annie_wang 已提交
551
**Return value**
A
annie_wangli 已提交
552

A
Annie_wang 已提交
553 554 555
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
556

A
annie_wangli 已提交
557
**Example**
A
annie_wangli 已提交
558

Z
zhangalong 已提交
559
  ```js
A
annie_wangli 已提交
560 561 562 563 564 565 566 567 568 569
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { 
      console.log('setAppAccountSyncEnable Success');
  }).catch((err) => {
      console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
  });
  ```

### setAssociatedData

A
annie_wangli 已提交
570
setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
571

A
Annie_wang 已提交
572
Sets data to be associated with an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
573

A
annie_wangli 已提交
574
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
575

A
annie_wangli 已提交
576
**Parameters**
A
annie_wangli 已提交
577

A
Annie_wang 已提交
578 579 580 581 582 583
| Name     | Type                       | Mandatory  | Description               |
| -------- | ------------------------- | ---- | ----------------- |
| name     | string                    | Yes   | Name of the target app account.          |
| key      | string                    | Yes   | Key of the data to set. The private key can be customized.|
| value    | string                    | Yes   | Value of the data to be set.        |
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the data associated with the specified app account is set.|
A
annie_wangli 已提交
584 585

**Example**
A
annie_wangli 已提交
586

Z
zhangalong 已提交
587
  ```js
A
annie_wangli 已提交
588 589 590 591 592 593 594
  app_account_instance.setAssociatedData("ZhangSan", "k001", "v001", (err) => { 
      console.log("setAssociatedData err: " + JSON.stringify(err));
  });
  ```

### setAssociatedData

A
annie_wangli 已提交
595
setAssociatedData(name: string, key: string, value: string): Promise&lt;void&gt;
A
annie_wangli 已提交
596

A
Annie_wang 已提交
597
Sets data to be associated with an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
598

A
annie_wangli 已提交
599 600 601
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
602

A
Annie_wang 已提交
603 604 605 606 607
| Name  | Type    | Mandatory  | Description               |
| ----- | ------ | ---- | ----------------- |
| name  | string | Yes   | Name of the target app account.          |
| key   | string | Yes   | Key of the data to set. The private key can be customized.|
| value | string | Yes   | Value of the data to be set.        |
A
annie_wangli 已提交
608

A
Annie_wang 已提交
609
**Return value**
A
annie_wangli 已提交
610

A
Annie_wang 已提交
611 612 613
| Type                 | Description                   |
| :------------------ | :-------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
614

A
annie_wangli 已提交
615
**Example**
A
annie_wangli 已提交
616

Z
zhangalong 已提交
617
  ```js
A
annie_wangli 已提交
618 619 620 621 622 623 624 625 626 627
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { 
      console.log('setAssociatedData Success');
  }).catch((err) => {
      console.log("setAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### getAccountCredential

A
annie_wangli 已提交
628
getAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
629

A
Annie_wang 已提交
630
Obtains the credentials (such as the digital password, face image, and PIN) of an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
631

A
annie_wangli 已提交
632
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
633

A
annie_wangli 已提交
634
**Parameters**
A
annie_wangli 已提交
635

A
Annie_wang 已提交
636 637 638 639 640
| Name           | Type                         | Mandatory  | Description            |
| -------------- | --------------------------- | ---- | -------------- |
| name           | string                      | Yes   | Name of the target app account.       |
| credentialType | string                      | Yes   | Type of the credential to obtain.|
| callback       | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the credential obtained.|
A
annie_wangli 已提交
641 642

**Example**
A
annie_wangli 已提交
643

Z
zhangalong 已提交
644
  ```js
A
annie_wangli 已提交
645 646 647 648 649 650 651 652 653
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { 
      console.log("getAccountCredential err: " + JSON.stringify(err));
      console.log('getAccountCredential result: ' + result);
  });
  ```

### getAccountCredential

A
annie_wangli 已提交
654
getAccountCredential(name: string, credentialType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
655

A
Annie_wang 已提交
656
Obtains the credential of an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
657

A
annie_wangli 已提交
658 659 660
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
661

A
Annie_wang 已提交
662 663 664 665
| Name           | Type    | Mandatory  | Description        |
| -------------- | ------ | ---- | ---------- |
| name           | string | Yes   | Name of the target app account.   |
| credentialType | string | Yes   | Type of the credential to obtain.|
A
annie_wangli 已提交
666

A
Annie_wang 已提交
667
**Return value**
A
annie_wangli 已提交
668

A
Annie_wang 已提交
669 670 671
| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
672

A
annie_wangli 已提交
673
**Example**
A
annie_wangli 已提交
674

Z
zhangalong 已提交
675
  ```js
A
annie_wangli 已提交
676 677 678 679 680 681 682 683 684 685
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { 
      console.log('getAccountCredential, result: ' + data);
  }).catch((err) => {
      console.log("getAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### getAccountExtraInfo

A
annie_wangli 已提交
686
getAccountExtraInfo(name: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
687

A
Annie_wang 已提交
688
Obtains additional information (information that can be converted into the string type) about an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
689

A
annie_wangli 已提交
690
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
691

A
annie_wangli 已提交
692
**Parameters**
A
annie_wangli 已提交
693

A
Annie_wang 已提交
694 695 696 697
| Name     | Type                         | Mandatory  | Description             |
| -------- | --------------------------- | ---- | --------------- |
| name     | string                      | Yes   | Name of the target app account.        |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the additional information of the specified app account.|
A
annie_wangli 已提交
698 699

**Example**
A
annie_wangli 已提交
700

Z
zhangalong 已提交
701
  ```js
A
annie_wangli 已提交
702 703 704 705 706 707 708 709 710
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { 
      console.log("getAccountExtraInfo err: " + JSON.stringify(err));
      console.log('getAccountExtraInfo result: ' + result);
  });
  ```

### getAccountExtraInfo

A
annie_wangli 已提交
711
getAccountExtraInfo(name: string): Promise&lt;string&gt;
A
annie_wangli 已提交
712

A
Annie_wang 已提交
713
Obtains additional information of an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
714

A
annie_wangli 已提交
715 716 717
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
718

A
Annie_wang 已提交
719 720 721
| Name | Type    | Mandatory  | Description     |
| ---- | ------ | ---- | ------- |
| name | string | Yes   | Name of the target app account.|
A
annie_wangli 已提交
722

A
Annie_wang 已提交
723
**Return value**
A
annie_wangli 已提交
724

A
Annie_wang 已提交
725 726 727
| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
728

A
annie_wangli 已提交
729
**Example**
A
annie_wangli 已提交
730

Z
zhangalong 已提交
731
  ```js
A
annie_wangli 已提交
732 733 734 735 736 737 738 739 740 741
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { 
      console.log('getAccountExtraInfo, result: ' + data);
  }).catch((err) => {
      console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
  });
  ```

### getAssociatedData

A
annie_wangli 已提交
742
getAssociatedData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
743

A
Annie_wang 已提交
744
Obtains data associated with an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
745

A
annie_wangli 已提交
746
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
747

A
annie_wangli 已提交
748
**Parameters**
A
annie_wangli 已提交
749

A
Annie_wang 已提交
750 751 752 753 754
| Name     | Type                         | Mandatory  | Description               |
| -------- | --------------------------- | ---- | ----------------- |
| name     | string                      | Yes   | Name of the target app account.          |
| key      | string                      | Yes   | Key of the data to obtain.        |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the data associated with the specified app account.|
A
annie_wangli 已提交
755 756

**Example**
A
annie_wangli 已提交
757

Z
zhangalong 已提交
758
  ```js
A
annie_wangli 已提交
759 760 761 762 763 764 765 766 767
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { 
      console.log("getAssociatedData err: " + JSON.stringify(err));
      console.log('getAssociatedData result: ' + result);
  });
  ```

### getAssociatedData

A
annie_wangli 已提交
768
getAssociatedData(name: string, key: string): Promise&lt;string&gt;
A
annie_wangli 已提交
769

A
Annie_wang 已提交
770
Obtains data associated with an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
771

A
annie_wangli 已提交
772 773 774
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
775

A
Annie_wang 已提交
776 777 778 779
| Name | Type    | Mandatory  | Description       |
| ---- | ------ | ---- | --------- |
| name | string | Yes   | Name of the target app account.  |
| key  | string | Yes   | Key of the data to obtain.|
A
annie_wangli 已提交
780

A
Annie_wang 已提交
781
**Return value**
A
annie_wangli 已提交
782

A
Annie_wang 已提交
783 784 785
| Type                   | Description                   |
| :-------------------- | :-------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
786

A
annie_wangli 已提交
787
**Example**
A
annie_wangli 已提交
788

Z
zhangalong 已提交
789
  ```js
A
annie_wangli 已提交
790 791 792 793 794 795 796 797 798 799
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { 
       console.log('getAssociatedData: ' + data);
  }).catch((err) => {
      console.log("getAssociatedData err: "  + JSON.stringify(err));
  });
  ```

### getAllAccessibleAccounts

A
annie_wangli 已提交
800
getAllAccessibleAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
801

A
Annie_wang 已提交
802
Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
803

A
annie_wangli 已提交
804
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
805

A
annie_wangli 已提交
806
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
807

A
annie_wangli 已提交
808
**Parameters**
A
annie_wangli 已提交
809

A
Annie_wang 已提交
810 811
| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
A
Annie_wang 已提交
812
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
A
annie_wangli 已提交
813 814

**Example**
A
annie_wangli 已提交
815

Z
zhangalong 已提交
816
  ```js
A
annie_wangli 已提交
817 818 819 820 821 822 823 824 825
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllAccessibleAccounts((err, data)=>{
  	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
  	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
  });
  ```

### getAllAccessibleAccounts

A
annie_wangli 已提交
826 827
getAllAccessibleAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

A
Annie_wang 已提交
828
Obtains information about all accessible app accounts. This API uses a promise to return the result.
A
annie_wangli 已提交
829

A
annie_wangli 已提交
830
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
831

A
annie_wangli 已提交
832
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
833

A
annie_wangli 已提交
834
**Parameters**
A
annie_wangli 已提交
835

A
Annie_wang 已提交
836 837
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
838
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
839

A
annie_wangli 已提交
840
**Example**
A
annie_wangli 已提交
841

Z
zhangalong 已提交
842
  ```js
A
annie_wangli 已提交
843 844 845 846 847 848 849 850 851 852
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllAccessibleAccounts().then((data) => { 
       console.log('getAllAccessibleAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
  });
  ```

### getAllAccounts

A
annie_wangli 已提交
853
getAllAccounts(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
854

A
Annie_wang 已提交
855
Obtains information about all app accounts of the specified app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
856

A
annie_wangli 已提交
857
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
858 859

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
860

A
annie_wangli 已提交
861
**Parameters**
A
annie_wangli 已提交
862

A
Annie_wang 已提交
863 864 865
| Name     | Type                                      | Mandatory  | Description       |
| -------- | ---------------------------------------- | ---- | --------- |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.   |
A
Annie_wang 已提交
866
| callback | AsyncCallback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
A
annie_wangli 已提交
867

A
annie_wangli 已提交
868
**Example**
A
annie_wangli 已提交
869

Z
zhangalong 已提交
870
  ```js
A
annie_wangli 已提交
871 872 873 874 875 876 877 878 879 880
  const appAccountManager = account.createAppAccountManager();
  const selfBundle = "com.example.actsgetallaaccounts";
  appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
  	console.debug("getAllAccounts err:" + JSON.stringify(err));
  	console.debug("getAllAccounts data:" + JSON.stringify(data));
  });
  ```

### getAllAccounts

A
annie_wangli 已提交
881 882
getAllAccounts(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;

A
Annie_wang 已提交
883
Obtains information about all app accounts of the specified app. This API uses a promise to return the result.
A
annie_wangli 已提交
884

A
annie_wangli 已提交
885
**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
A
annie_wangli 已提交
886

A
annie_wangli 已提交
887
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
888

A
annie_wangli 已提交
889
**Parameters**
A
annie_wangli 已提交
890

A
Annie_wang 已提交
891 892 893
| Name  | Type    | Mandatory  | Description    |
| ----- | ------ | ---- | ------ |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
annie_wangli 已提交
894

A
annie_wangli 已提交
895
**Parameters**
A
annie_wangli 已提交
896

A
Annie_wang 已提交
897 898
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
A
Annie_wang 已提交
899
| Promise&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
900

A
annie_wangli 已提交
901
**Example**
A
annie_wangli 已提交
902

Z
zhangalong 已提交
903
  ```js
A
annie_wangli 已提交
904 905 906 907 908 909 910 911 912 913 914
  const appAccountManager = account_appAccount.createAppAccountManager();
  const selfBundle = "com.example.actsgetallaaccounts";
  appAccountManager.getAllAccounts(selfBundle).then((data) => { 
       console.log('getAllAccounts: ' + data);
  }).catch((err) => {
      console.log("getAllAccounts err: "  + JSON.stringify(err));
  });
  ```

### on('change')

A
annie_wangli 已提交
915
on(type: 'change', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
A
annie_wangli 已提交
916

A
Annie_wang 已提交
917
Subscribes to the account change events of the specified account owners. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
918

A
annie_wangli 已提交
919
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
920

A
annie_wangli 已提交
921
**Parameters**
A
annie_wangli 已提交
922

A
Annie_wang 已提交
923 924 925 926
| Name     | Type                                      | Mandatory  | Description                            |
| -------- | ---------------------------------------- | ---- | ------------------------------ |
| type     | 'change'                                 | Yes   | Account change events to subscribe to. The subscriber will receive a notification when the account owners update their accounts.|
| owners   | Array&lt;string&gt;                      | Yes   | Account owners.                     |
A
Annie_wang 已提交
927
| callback | Callback&lt;Array&lt;[AppAccountInfo](#appaccountinfo)&gt;&gt; | Yes   | Callback invoked to return the account changes.          |
A
annie_wangli 已提交
928 929

**Example**
A
annie_wangli 已提交
930

Z
zhangalong 已提交
931
  ```js
A
annie_wangli 已提交
932 933 934 935 936 937 938 939 940 941 942 943 944 945
  const appAccountManager = account.createAppAccountManager();
  function changeOnCallback(data){
  	console.debug("receive change data:" + JSON.stringify(data));
  }
  try{
  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  }
  catch(err){
  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  }
  ```

### off('change')

A
annie_wangli 已提交
946
off(type: 'change', callback?: Callback<Array\<AppAccountInfo>>): void
A
annie_wangli 已提交
947

A
Annie_wang 已提交
948
Unsubscribes from the account change events. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
949

A
annie_wangli 已提交
950 951 952
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
953

A
Annie_wang 已提交
954 955 956
| Name     | Type                              | Mandatory  | Description          |
| -------- | -------------------------------- | ---- | ------------ |
| type     | 'change'                         | Yes   | Account change events to unsubscribe from.   |
A
Annie_wang 已提交
957
| callback | Callback<Array\<[AppAccountInfo](#appaccountinfo)>> | No   | Callback used to report the account changes.|
A
annie_wangli 已提交
958

A
annie_wangli 已提交
959
**Example**
A
annie_wangli 已提交
960

Z
zhangalong 已提交
961
  ```js
A
annie_wangli 已提交
962 963 964 965 966
  const appAccountManager = account.createAppAccountManager();
  function changeOnCallback(data){
  	console.debug("receive change data:" + JSON.stringify(data));
  	appAccountManager.off('change', function(){
  		console.debug("off finish");
A
annie_wangli 已提交
967
  	})
A
annie_wangli 已提交
968 969 970 971 972 973 974 975 976
  }
  try{
  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
  }
  catch(err){
  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
  }
  ```

A
annie_wangli 已提交
977 978
### authenticate<sup>8+</sup>

A
annie_wangli 已提交
979
authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
980

A
Annie_wang 已提交
981
Authenticates an app account to obtain an Open Authorization (OAuth) token. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
982

A
annie_wangli 已提交
983 984 985
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
986

A
Annie_wang 已提交
987 988
| Name     | Type                   | Mandatory  | Description             |
| -------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
989
| name     | string                | Yes   | Name of the target app account.    |
A
Annie_wang 已提交
990 991 992
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                | Yes   | Authentication type.          |
| options  | {[key: string]: any}  | Yes   | Options for the authentication.      |
A
Annie_wang 已提交
993
| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
994

A
annie_wangli 已提交
995
**Example**
A
annie_wangli 已提交
996

Z
zhangalong 已提交
997
  ```js
A
annie_wangli 已提交
998
  import featureAbility from '@ohos.ability.featureAbility';
A
annie_wangli 已提交
999

A
annie_wangli 已提交
1000 1001 1002 1003
  function onResultCallback(code, result) {
      console.log("resultCode: "  + code);
      console.log("result: "  + JSON.stringify(result));
  }
A
annie_wangli 已提交
1004

A
annie_wangli 已提交
1005 1006 1007 1008 1009 1010
  function onRequestRedirectedCallback(request) {
      let abilityStartSetting = {want: request};
      featureAbility.startAbility(abilityStartSetting, (err)=>{
          console.log("startAbility err: " + JSON.stringify(err));
      });
  }
A
annie_wangli 已提交
1011

A
annie_wangli 已提交
1012 1013 1014 1015 1016 1017 1018 1019 1020
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "readAge", {}, {
    onResult: onResultCallback,
    onRequestRedirected: onRequestRedirectedCallback
  });
  ```

### getOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1021
getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
A
annie_wangli 已提交
1022

A
Annie_wang 已提交
1023
Obtains the OAuth token of an app account based on the specified authentication type. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1024

A
annie_wangli 已提交
1025 1026 1027
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1028

A
Annie_wang 已提交
1029 1030 1031 1032 1033 1034
| Name     | Type                         | Mandatory  | Description         |
| -------- | --------------------------- | ---- | ----------- |
| name     | string                      | Yes   | Name of the target app account.   |
| owner    | string                      | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string                      | Yes   | Authentication type.      |
| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1035

A
annie_wangli 已提交
1036
**Example**
A
annie_wangli 已提交
1037

Z
zhangalong 已提交
1038
  ```js
A
annie_wangli 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", (err, data) => {
       console.log('getOAuthToken err: ' + JSON.stringify(err));
       console.log('getOAuthToken token: ' + data);
  });
  ```

### getOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1048
getOAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
A
annie_wangli 已提交
1049

A
Annie_wang 已提交
1050
Obtains the OAuth token of an app account based on the specified authentication type. This API uses a promise to return the result.
A
annie_wangli 已提交
1051

A
annie_wangli 已提交
1052
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1053

A
annie_wangli 已提交
1054
**Parameters**
A
annie_wangli 已提交
1055

A
Annie_wang 已提交
1056 1057 1058 1059 1060
| Name     | Type    | Mandatory  | Description         |
| -------- | ------ | ---- | ----------- |
| name     | string | Yes   | Name of the target app account.   |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
| authType | string | Yes   | Authentication type.      |
A
annie_wangli 已提交
1061

A
annie_wangli 已提交
1062
**Parameters**
A
annie_wangli 已提交
1063

A
Annie_wang 已提交
1064 1065 1066
| Type                   | Description                   |
| --------------------- | --------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1067 1068

**Example**
A
annie_wangli 已提交
1069

Z
zhangalong 已提交
1070
  ```js
A
annie_wangli 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge").then((data) => {
       console.log('getOAuthToken token: ' + data);
  }).catch((err) => {
      console.log("getOAuthToken err: "  + JSON.stringify(err));
  });
  ```

### setOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1081
setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1082

A
Annie_wang 已提交
1083
Sets an OAuth token for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1084

A
annie_wangli 已提交
1085 1086 1087
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1088

A
Annie_wang 已提交
1089 1090 1091 1092 1093 1094
| Name     | Type                       | Mandatory  | Description      |
| -------- | ------------------------- | ---- | -------- |
| name     | string                    | Yes   | Name of the target app account.|
| authType | string                    | Yes   | Authentication type.   |
| token    | string                    | Yes   | OAuth token to set.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.|
A
annie_wangli 已提交
1095

A
annie_wangli 已提交
1096
**Example**
A
annie_wangli 已提交
1097

Z
zhangalong 已提交
1098
  ```js
A
annie_wangli 已提交
1099 1100 1101 1102 1103 1104 1105 1106
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx", (err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### setOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1107
setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1108

A
Annie_wang 已提交
1109
Sets an OAuth token for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1110

A
annie_wangli 已提交
1111
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1112

A
annie_wangli 已提交
1113
**Parameters**
A
annie_wangli 已提交
1114

A
Annie_wang 已提交
1115 1116 1117 1118 1119
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| name     | string | Yes   | Name of the target app account.|
| authType | string | Yes   | Authentication type.   |
| token    | string | Yes   | OAuth token to set.|
A
annie_wangli 已提交
1120

A
annie_wangli 已提交
1121
**Parameters**
A
annie_wangli 已提交
1122

A
Annie_wang 已提交
1123 1124 1125
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1126 1127

**Example**
A
annie_wangli 已提交
1128

Z
zhangalong 已提交
1129
  ```js
A
annie_wangli 已提交
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthToken("LiSi", "readAge", "xxxx").then(() => {
      console.log('setOAuthToken successfully');
  }).catch((err) => {
      console.log('setOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### deleteOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1140
deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1141

A
Annie_wang 已提交
1142
Deletes the specified OAuth token for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1143

A
annie_wangli 已提交
1144 1145 1146
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1147

A
Annie_wang 已提交
1148 1149 1150 1151 1152 1153 1154
| Name     | Type                       | Mandatory  | Description          |
| -------- | ------------------------- | ---- | ------------ |
| name     | string                    | Yes   | Name of the target app account.    |
| owner    | string                    | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string                    | Yes   | Authentication type.       |
| token    | string                    | Yes   | OAuth token to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.    |
A
annie_wangli 已提交
1155

A
annie_wangli 已提交
1156
**Example**
A
annie_wangli 已提交
1157

Z
zhangalong 已提交
1158
  ```js
A
annie_wangli 已提交
1159 1160 1161 1162 1163 1164 1165 1166
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx", (err) => {
       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
  });
  ```

### deleteOAuthToken<sup>8+</sup>

A
annie_wangli 已提交
1167
deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;
A
annie_wangli 已提交
1168

A
Annie_wang 已提交
1169
Deletes the specified OAuth token for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1170

A
annie_wangli 已提交
1171 1172 1173
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1174

A
Annie_wang 已提交
1175 1176 1177 1178 1179 1180
| Name     | Type    | Mandatory  | Description          |
| -------- | ------ | ---- | ------------ |
| name     | string | Yes   | Name of the target app account.    |
| owner    | string | Yes   | Owner of the app account. The value is the bundle name of the app. |
| authType | string | Yes   | Authentication type.       |
| token    | string | Yes   | OAuth token to delete.|
A
annie_wangli 已提交
1181

A
annie_wangli 已提交
1182
**Parameters**
A
annie_wangli 已提交
1183

A
Annie_wang 已提交
1184 1185 1186
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1187

A
annie_wangli 已提交
1188
**Example**
A
annie_wangli 已提交
1189

Z
zhangalong 已提交
1190
  ```js
A
annie_wangli 已提交
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "readAge", "xxxxx").then(() => {
       console.log('deleteOAuthToken successfully');
  }).catch((err) => {
      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
  });
  ```

### setOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1201
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
A
annie_wangli 已提交
1202

A
Annie_wang 已提交
1203
Sets the visibility of an OAuth token to an app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1204

A
annie_wangli 已提交
1205
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1206

A
annie_wangli 已提交
1207
**Parameters**
A
annie_wangli 已提交
1208

A
Annie_wang 已提交
1209 1210 1211 1212 1213 1214 1215
| Name       | Type                       | Mandatory  | Description                       |
| ---------- | ------------------------- | ---- | ------------------------- |
| name       | string                    | Yes   | Name of the target app account.                 |
| authType   | string                    | Yes   | Authentication type.                    |
| bundleName | string                    | Yes   | Bundle name of the app.             |
| isVisible  | boolean                   | Yes   | Whether the OAuth token is visible to the app. The value **true** means visible, and the value **false** means the opposite.|
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.                 |
A
annie_wangli 已提交
1216 1217

**Example**
A
annie_wangli 已提交
1218

Z
zhangalong 已提交
1219
  ```js
A
annie_wangli 已提交
1220 1221 1222 1223 1224 1225 1226 1227
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err) => {
       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### setOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1228
setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;
A
annie_wangli 已提交
1229

A
Annie_wang 已提交
1230
Sets the visibility of an OAuth token to an app. This API uses a promise to return the result.
A
annie_wangli 已提交
1231

A
annie_wangli 已提交
1232 1233 1234
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1235

A
Annie_wang 已提交
1236 1237 1238 1239 1240 1241
| Name       | Type     | Mandatory  | Description          |
| ---------- | ------- | ---- | ------------ |
| name       | string  | Yes   | Name of the target app account.    |
| authType   | string  | Yes   | Authentication type.       |
| bundleName | string  | Yes   | Bundle name of the app.|
| isVisible  | boolean | Yes   | Whether the OAuth token is visible to the app.       |
A
annie_wangli 已提交
1242

A
annie_wangli 已提交
1243
**Parameters**
A
annie_wangli 已提交
1244

A
Annie_wang 已提交
1245 1246 1247
| Type                 | Description                   |
| ------------------- | --------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1248

A
annie_wangli 已提交
1249
**Example**
A
annie_wangli 已提交
1250

Z
zhangalong 已提交
1251
  ```js
A
annie_wangli 已提交
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then(() => {
      console.log('setOAuthTokenVisibility successfully');
  }).catch((err) => {
      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### checkOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1262
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
A
annie_wangli 已提交
1263

A
Annie_wang 已提交
1264
Checks whether an OAuth token is visible to an app. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1265

A
annie_wangli 已提交
1266
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1267

A
annie_wangli 已提交
1268
**Parameters**
A
annie_wangli 已提交
1269

A
Annie_wang 已提交
1270 1271 1272 1273 1274 1275
| Name       | Type                          | Mandatory  | Description         |
| ---------- | ---------------------------- | ---- | ----------- |
| name       | string                       | Yes   | Name of the target app account.   |
| authType   | string                       | Yes   | Authentication type.      |
| bundleName | string                       | Yes   | Bundle name of the app.|
| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1276 1277

**Example**
A
annie_wangli 已提交
1278

Z
zhangalong 已提交
1279
  ```js
A
annie_wangli 已提交
1280 1281 1282 1283 1284 1285 1286 1287 1288
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true, (err, data) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
  });
  ```

### checkOAuthTokenVisibility<sup>8+</sup>

A
annie_wangli 已提交
1289
checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
A
annie_wangli 已提交
1290

A
Annie_wang 已提交
1291
Checks whether an OAuth token is visible to an app. This API uses a promise to return the result.
A
annie_wangli 已提交
1292

A
annie_wangli 已提交
1293 1294 1295
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1296

A
Annie_wang 已提交
1297 1298 1299 1300 1301
| Name       | Type    | Mandatory  | Description           |
| ---------- | ------ | ---- | ------------- |
| name       | string | Yes   | Name of the target app account.     |
| authType   | string | Yes   | Authentication type.        |
| bundleName | string | Yes   | Bundle name of the app.|
A
annie_wangli 已提交
1302

A
annie_wangli 已提交
1303
**Parameters**
A
annie_wangli 已提交
1304

A
Annie_wang 已提交
1305 1306 1307
| Type                    | Description                   |
| ---------------------- | --------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1308

A
annie_wangli 已提交
1309
**Example**
A
annie_wangli 已提交
1310

Z
zhangalong 已提交
1311
  ```js
A
annie_wangli 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkOAuthTokenVisibility("LiSi", "readAge", "com.example.ohos.accountjsdemo", true).then((data) => {
      console.log('checkOAuthTokenVisibility isVisible: ' + data);
  }).catch((err) => {
      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
  });
  ```

### getAllOAuthTokens<sup>8+</sup>

A
annie_wangli 已提交
1322
getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt;): void
A
annie_wangli 已提交
1323

A
Annie_wang 已提交
1324
Obtains all OAuth tokens visible to the caller for an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1325

A
annie_wangli 已提交
1326
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1327

A
annie_wangli 已提交
1328
**Parameters**
A
annie_wangli 已提交
1329

A
Annie_wang 已提交
1330 1331 1332 1333 1334
| Name     | Type                                      | Mandatory  | Description         |
| -------- | ---------------------------------------- | ---- | ----------- |
| name     | string                                   | Yes   | Name of the target app account.   |
| owner    | string                                   | Yes   | Owner of the app account. The value is the bundle name of the app.|
| callback | AsyncCallback&lt;Array&lt; [OAuthTokenInfo](#oauthtokeninfo8)&gt;&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1335 1336

**Example**
A
annie_wangli 已提交
1337

Z
zhangalong 已提交
1338
  ```js
A
annie_wangli 已提交
1339 1340 1341 1342 1343 1344 1345 1346 1347
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => {
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  });
  ```

### getAllOAuthTokens<sup>8+</sup>

A
annie_wangli 已提交
1348
getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
A
annie_wangli 已提交
1349

A
Annie_wang 已提交
1350
Obtains all OAuth tokens visible to the caller for an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1351

A
annie_wangli 已提交
1352 1353 1354
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1355

A
Annie_wang 已提交
1356 1357 1358 1359
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| name  | string | Yes   | Name of the target app account.   |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
annie_wangli 已提交
1360

A
annie_wangli 已提交
1361
**Parameters**
A
annie_wangli 已提交
1362

A
Annie_wang 已提交
1363 1364 1365
| Type                                      | Description                   |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt; [OAuthTokenInfo](#oauthtokeninfo8)&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1366

A
annie_wangli 已提交
1367
**Example**
A
annie_wangli 已提交
1368

Z
zhangalong 已提交
1369
  ```js
A
annie_wangli 已提交
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => {
       console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
  });
  ```

### getOAuthList<sup>8+</sup>

A
annie_wangli 已提交
1380
getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
A
annie_wangli 已提交
1381

A
Annie_wang 已提交
1382
Obtains a list of authorized OAuth tokens of an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1383

A
annie_wangli 已提交
1384
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1385

A
annie_wangli 已提交
1386
**Parameters**
A
annie_wangli 已提交
1387

A
Annie_wang 已提交
1388 1389 1390 1391 1392
| Name     | Type                                      | Mandatory  | Description                     |
| -------- | ---------------------------------------- | ---- | ----------------------- |
| name     | string                                   | Yes   | Name of the target app account.               |
| authType | string                                   | Yes   | Authorization type.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the result.               |
A
annie_wangli 已提交
1393 1394

**Example**
A
annie_wangli 已提交
1395

Z
zhangalong 已提交
1396
  ```js
A
annie_wangli 已提交
1397 1398 1399 1400 1401 1402 1403 1404 1405
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge", (err, data) => {
       console.log('getOAuthList err: ' + JSON.stringify(err));
       console.log('getOAuthList data: ' + JSON.stringify(data));
  });
  ```

### getOAuthList<sup>8+</sup>

A
annie_wangli 已提交
1406
getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
A
annie_wangli 已提交
1407

A
Annie_wang 已提交
1408
Obtains a list of authorized OAuth tokens of an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1409

A
annie_wangli 已提交
1410 1411 1412
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1413

A
Annie_wang 已提交
1414 1415 1416 1417
| Name     | Type    | Mandatory  | Description                     |
| -------- | ------ | ---- | ----------------------- |
| name     | string | Yes   | Name of the target app account.               |
| authType | string | Yes   | Authorization type.|
A
annie_wangli 已提交
1418

A
annie_wangli 已提交
1419
**Parameters**
A
annie_wangli 已提交
1420

A
Annie_wang 已提交
1421 1422 1423
| Type                                | Description                   |
| ---------------------------------- | --------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1424

A
annie_wangli 已提交
1425
**Example**
A
annie_wangli 已提交
1426

Z
zhangalong 已提交
1427
  ```js
A
annie_wangli 已提交
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "readAge").then((data) => {
       console.log('getOAuthList data: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getOAuthList err: "  + JSON.stringify(err));
  });
  ```

### getAuthenticatorCallback<sup>8+</sup>

A
annie_wangli 已提交
1438
getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
A
annie_wangli 已提交
1439

A
Annie_wang 已提交
1440
Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1441

A
annie_wangli 已提交
1442 1443 1444
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1445

A
Annie_wang 已提交
1446 1447 1448
| Name      | Type                                      | Mandatory  | Description      |
| --------- | ---------------------------------------- | ---- | -------- |
| sessionId | string                                   | Yes   | ID of the authentication session.|
A
Annie_wang 已提交
1449
| callback  | AsyncCallback&lt;[AuthenticatorCallback](#authenticatorcallback8)&gt; | Yes   | Callback invoked to return the result.|
A
annie_wangli 已提交
1450

A
annie_wangli 已提交
1451
**Example**
A
annie_wangli 已提交
1452

Z
zhangalong 已提交
1453
  ```js
A
Annie_wang 已提交
1454
  import featureAbility from '@ohos.ability.featureAbility';
A
annie_wangli 已提交
1455 1456
  const appAccountManager = account_appAccount.createAppAccountManager();
  featureAbility.getWant((err, want) => {
A
annie_wangli 已提交
1457
    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
A
annie_wangli 已提交
1458
    appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
A
annie_wangli 已提交
1459
        if (err.code != account_appAccount.ResultCode.SUCCESS) {
A
annie_wangli 已提交
1460 1461 1462
            console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
            return;
        }
A
annie_wangli 已提交
1463 1464 1465 1466 1467
        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                      [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
        callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1468 1469 1470 1471 1472 1473
    });
  });
  ```

### getAuthenticatorCallback<sup>8+</sup>

A
annie_wangli 已提交
1474
getAuthenticatorCallback(sessionId: string): Promise&lt;AuthenticatorCallback&gt;
A
annie_wangli 已提交
1475

A
Annie_wang 已提交
1476
Obtains the authenticator callback for an authentication session. This API uses a promise to return the result.
A
annie_wangli 已提交
1477

A
annie_wangli 已提交
1478
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1479

A
annie_wangli 已提交
1480
**Parameters**
A
annie_wangli 已提交
1481

A
Annie_wang 已提交
1482 1483 1484
| Name      | Type    | Mandatory  | Description      |
| --------- | ------ | ---- | -------- |
| sessionId | string | Yes   | ID of the authentication session.|
A
annie_wangli 已提交
1485

A
annie_wangli 已提交
1486
**Parameters**
A
annie_wangli 已提交
1487

A
Annie_wang 已提交
1488 1489
| Type                                  | Description                   |
| ------------------------------------ | --------------------- |
A
Annie_wang 已提交
1490
| Promise&lt;[AuthenticatorCallback](#authenticatorcallback8)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1491 1492

**Example**
A
annie_wangli 已提交
1493

Z
zhangalong 已提交
1494
  ```js
A
annie_wangli 已提交
1495 1496
  const appAccountManager = account_appAccount.createAppAccountManager();
  featureAbility.getWant().then((want) => {
A
annie_wangli 已提交
1497
      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
A
annie_wangli 已提交
1498
      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
1499 1500 1501 1502 1503
          var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                        [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
      }).catch((err) => {
          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
      });
  }).catch((err) => {
      console.log("getWant err: "  + JSON.stringify(err));
  });
  ```

### getAuthenticatorInfo<sup>8+</sup>

A
annie_wangli 已提交
1514
getAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void
A
annie_wangli 已提交
1515

A
Annie_wang 已提交
1516
Obtains authenticator information of an app account. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1517

A
annie_wangli 已提交
1518 1519 1520
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
annie_wangli 已提交
1521

A
Annie_wang 已提交
1522 1523 1524
| Name     | Type                                    | Mandatory  | Description         |
| -------- | -------------------------------------- | ---- | ----------- |
| owner    | string                                 | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
1525
| callback | AsyncCallback&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Yes   | Callback invoked to return the result.   |
A
annie_wangli 已提交
1526

A
annie_wangli 已提交
1527
**Example**
A
annie_wangli 已提交
1528

Z
zhangalong 已提交
1529
  ```js
A
annie_wangli 已提交
1530 1531 1532 1533 1534 1535 1536 1537 1538
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
      console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
  });
  ```

### getAuthenticatorInfo<sup>8+</sup>

A
annie_wangli 已提交
1539
getAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;
A
annie_wangli 已提交
1540

A
Annie_wang 已提交
1541
Obtains authenticator information of an app account. This API uses a promise to return the result.
A
annie_wangli 已提交
1542

A
annie_wangli 已提交
1543
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
1544

A
annie_wangli 已提交
1545
**Parameters**
A
annie_wangli 已提交
1546

A
Annie_wang 已提交
1547 1548 1549
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
annie_wangli 已提交
1550

A
annie_wangli 已提交
1551
**Parameters**
A
annie_wangli 已提交
1552

A
Annie_wang 已提交
1553 1554
| Type                              | Description                   |
| -------------------------------- | --------------------- |
A
Annie_wang 已提交
1555
| Promise&lt;[AuthenticatorInfo](#authenticatorinfo8)&gt; | Promise used to return the result.|
A
annie_wangli 已提交
1556 1557

**Example**
A
annie_wangli 已提交
1558

Z
zhangalong 已提交
1559
  ```js
A
annie_wangli 已提交
1560 1561 1562 1563 1564 1565 1566 1567
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => { 
       console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
  });
  ```

A
Annie_wang 已提交
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
### checkAppAccess<sup>9+</sup>

checkAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void

Checks whether an app account is authorized to access an app. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type                        | Mandatory | Description            |
| ---------- | ---------------------------- | ----- | ---------------- |
| name       | string                       | Yes   | Name of the target app account.  |
A
Annie_wang 已提交
1581
| bundleName | string                       | Yes   | Bundle name of the app to access.|
A
Annie_wang 已提交
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result.  |

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => {
      console.log('checkAppAccess: ' + JSON.stringify(data));
      console.log("checkAppAccess err: "  + JSON.stringify(err));
  });
  ```

### checkAppAccess<sup>9+</sup>

checkAppAccess(name: string, bundleName: string): Promise&lt;boolean&gt;

Checks whether an app account is authorized to access an app. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name     | Type  | Mandatory  | Description            |
| ---------- | ------ | ----- | ---------------- |
| name       | string | Yes   | Name of the target app account.  |
A
Annie_wang 已提交
1607
| bundleName | string | Yes   | Bundle name of the app to access.|
A
Annie_wang 已提交
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

**Parameters**

| Type                  | Description                             |
| ---------------------- | --------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo").then((data) => {
       console.log('checkAppAccess: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("checkAppAccess err: "  + JSON.stringify(err));
  });
  ```

### deleteAccountCredential<sup>9+</sup>

deleteAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;void&gt;): void

Deletes the credential of an app account. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description           |
| -------------- | ------------------------- | ----- | -------------- |
| name           | string                    | Yes   | Name of the target app account.|
| credentialType | string                    | Yes   | Type of the credential to delete.     |
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.|

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccountCredential("zhangsan", "pin", (err, data) => {
      console.log('deleteAccountCredential: ' + JSON.stringify(data));
      console.log("deleteAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### deleteAccountCredential<sup>9+</sup>

deleteAccountCredential(name: string, credentialType: string): Promise&lt;void&gt;

Deletes the credential of an app account. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type  | Mandatory  | Description           |
| -------------- | ------ | ----- | --------------- |
| name           | string | Yes   | Name of the target app account.|
| credentialType | string | Yes   | Type of the credential to delete.      |

**Parameters**

| Type               | Description                             |
| ------------------- | -------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.deleteAccountCredential("zhangsan", "pin").then((data) => {
       console.log('deleteAccountCredential: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("deleteAccountCredential err: "  + JSON.stringify(err));
  });
  ```

### checkAccountLabels<sup>9+</sup>

checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;, callback: AsyncCallback&lt;boolean&gt;): void;

Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
| name           | string                    | Yes   | Name of the target app account. |
| owner          | string                    | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
1698
| labels         | Array&lt;string&gt;       | Yes   | Labels to check.      |
A
Annie_wang 已提交
1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724
| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result. |

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => {
      console.log('checkAccountLabels: ' + JSON.stringify(data));
      console.log("checkAccountLabels err: "  + JSON.stringify(err));
  });
  ```

### checkAccountLabels<sup>9+</sup>

checkAccountLabels(name: string, owner: string, labels: Array&lt;string&gt;): Promise&lt;void&gt;

Checks whether an app account has specific labels. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
| name           | string                    | Yes   | Name of the target app account. |
| owner          | string                    | Yes   | Owner of the app account. The value is the bundle name of the app.|
A
Annie_wang 已提交
1725
| labels         | Array&lt;string&gt;       | Yes   | Labels to check.      |
A
Annie_wang 已提交
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756

**Parameters**

| Type               | Description                             |
| ------------------- | -------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo").then((data) => {
       console.log('checkAccountLabels: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("checkAccountLabels err: "  + JSON.stringify(err));
  });
  ```

### selectAccountsByOptions<sup>9+</sup>

selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;);

Selects the accounts accessible to the requester based on the options. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                                | Mandatory | Description            |
| -------------- | ----------------------------------- | ----- | --------------- |
| options        | SelectAccountsOptions               | Yes   | Options for selecting accounts.  |
A
Annie_wang 已提交
1757
| callback       | AsyncCallback&lt;[AppAccountInfo](#appaccountinfo)&gt; | Yes   | Callback invoked to return the result. |
A
Annie_wang 已提交
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  var options = {
    allowedOwners: ["com.example.ohos.accountjsdemo"]
  };
  appAccountManager.selectAccountsByOptions(options, (err, data) => {
      console.log('selectAccountsByOptions: ' + JSON.stringify(data));
      console.log("selectAccountsByOptions err: "  + JSON.stringify(err));
  });
  ```

### selectAccountsByOptions<sup>9+</sup>

selectAccountsByOptions(options: SelectAccountsOptions): Promise&lt;void&gt;

Selects the accounts accessible to the requester based on the options. This API uses a promise to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name        | Type                      | Mandatory | Description            |
| -------------- | ------------------------- | ----- | --------------- |
A
Annie_wang 已提交
1784
| options        | [SelectAccountsOptions](#selectaccountsoptions9)     | Yes   | Options for selecting accounts.  |
A
Annie_wang 已提交
1785 1786 1787 1788 1789

**Parameters**

| Type               | Description                             |
| ------------------- | -------------------------------- |
A
Annie_wang 已提交
1790
| Promise&lt;[AppAccountInfo](#appaccountinfo)&gt; | Promise used to return the result.|
A
Annie_wang 已提交
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  var options = {
    allowedOwners: ["com.example.ohos.accountjsdemo"]
  };
  appAccountManager.selectAccountsByOptions(options).then((data) => {
       console.log('selectAccountsByOptions: ' + JSON.stringify(data));
  }).catch((err) => {
      console.log("selectAccountsByOptions err: "  + JSON.stringify(err));
  });
  ```

### verifyCredential<sup>9+</sup>

verifyCredential(name: string, owner: string, callback: AuthenticatorCallback): void;

Verifies the user credential. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| name     | string                | Yes   | Name of the target app account.         |
| owner    | string                | Yes   | Owner of the app account. The value is the bundle name of the app.       |
A
Annie_wang 已提交
1820
| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the verification result.|
A
Annie_wang 已提交
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", {
    onResult: (resultCode, result) => {
      console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
      console.log("verifyCredential onResult, result:" + JSON.stringify(result));
    },
    onRequestRedirected: (request) => {
      console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
    }
  });
  ```

### verifyCredential<sup>9+</sup>

verifyCredential(name: string, owner: string, options, callback: AuthenticatorCallback): void;

Verifies the user credential. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                   | Mandatory | Description                    |
| -------- | ----------------------- | ----- | ----------------------- |
| name     | string                  | Yes   | Name of the target app account.         |
| owner    | string                  | Yes   | Owner of the app account. The value is the bundle name of the app.       |
A
Annie_wang 已提交
1851 1852
| options  | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes   | Options for verifying the user credential.         |
| callback | [AuthenticatorCallback](#authenticatorcallback8)   | Yes   | Authenticator callback invoked to return the verification result.|
A
Annie_wang 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  var options = {
    credentialType: "pin",
    credential: "123456"
  };
  appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", options, {
    onResult: (resultCode, result) => {
      console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode));
      console.log("verifyCredential onResult, result:" + JSON.stringify(result));
    },
    onRequestRedirected: (request) => {
      console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request));
    }
  });
  ```

### setAuthenticatorProperties<sup>9+</sup>

setAuthenticatorProperties(owner: string, callback: AuthenticatorCallback): void;

Sets authenticator properties. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| owner    | string                | Yes   | Owner of the authenticator.         |
A
Annie_wang 已提交
1886 1887
| options  | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.         |
| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", {
    onResult: (resultCode, result) => {
      console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
      console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
    },
    onRequestRedirected: (request) => {
      console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
    }
  });
  ```

### setAuthenticatorProperties<sup>9+</sup>

setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthenticatorCallback): void;

Sets authenticator properties. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**

| Name   | Type                 | Mandatory | Description                    |
| -------- | --------------------- | ----- | ----------------------- |
| owner    | string                | Yes   | Owner of the authenticator.         |
A
Annie_wang 已提交
1917 1918
| options  | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.         |
| callback | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  var options = {
    properties: {"prop1": "value1"}
  };
  appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", options, {
    onResult: (resultCode, result) => {
      console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode));
      console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result));
    },
    onRequestRedirected: (request) => {
      console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request));
    }
  });
  ```

A
annie_wangli 已提交
1938 1939
## AppAccountInfo

A
annie_wangli 已提交
1940 1941
Defines app account information.

A
annie_wangli 已提交
1942 1943
**System capability**: SystemCapability.Account.AppAccount

A
Annie_wang 已提交
1944 1945 1946 1947
| Name  | Type    | Mandatory  | Description         |
| ----- | ------ | ---- | ----------- |
| owner | string | Yes   | Owner of the app account. The value is the bundle name of the app.|
| name  | string | Yes   | Name of the target app account.   |
A
annie_wangli 已提交
1948 1949

## OAuthTokenInfo<sup>8+</sup>
A
annie_wangli 已提交
1950

A
Annie_wang 已提交
1951
Defines OAuth token information.
A
annie_wangli 已提交
1952

A
annie_wangli 已提交
1953 1954
**System capability**: SystemCapability.Account.AppAccount

A
Annie_wang 已提交
1955 1956 1957 1958
| Name     | Type    | Mandatory  | Description      |
| -------- | ------ | ---- | -------- |
| authType | string | Yes   | Authentication type.|
| token    | string | Yes   | Value of the token.  |
1959
| account<sup>9+</sup> | AppAccountInfo | No    | Account information of the token.  |
A
annie_wangli 已提交
1960 1961 1962 1963 1964

## AuthenticatorInfo<sup>8+</sup>

Defines OAuth authenticator information.

A
annie_wangli 已提交
1965 1966
**System capability**: SystemCapability.Account.AppAccount

A
Annie_wang 已提交
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
| Name    | Type    | Mandatory  | Description        |
| ------- | ------ | ---- | ---------- |
| owner   | string | Yes   | Owner of the authenticator. The value is the bundle name of the app.|
| iconId  | string | Yes   | ID of the authenticator icon. |
| labelId | string | Yes   | ID of the authenticator label. |

## SelectAccountsOptions<sup>9+</sup>

Represents the options for selecting accounts.

**System capability**: SystemCapability.Account.AppAccount

| Name         | Type                        | Mandatory | Description               |
| --------------- | --------------------------- | ----- | ------------------- |
A
Annie_wang 已提交
1981
| allowedAccounts | Array&lt;[AppAccountInfo](#appAccountinfo)&gt; | No   | Allowed accounts.     |
A
Annie_wang 已提交
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
| allowedOwners   | Array&lt;string&gt;         | No   | Allowed account owners.|
| requiredLabels  | Array&lt;string&gt;         | No   | Labels required for the authenticator.   |

## VerifyCredentialOptions<sup>9+</sup>

Represents the options for verifying the user credential.

**System capability**: SystemCapability.Account.AppAccount

| Name         | Type                  | Mandatory | Description          |
| -------------- | ---------------------- | ----- | -------------- |
| credentialType | string                 | No   | Type of the credential to verify.     |
| credential     | string                 | No   | Credential value.     |
| parameters     | {[key:string]: Object} | No   | Customized parameters.|


## SetPropertiesOptions<sup>9+</sup>

Represents the options for setting authenticator properties.

**System capability**: SystemCapability.Account.AppAccount

| Name    | Type                   | Mandatory | Description          |
| ---------- | ---------------------- | ----- | -------------- |
A
Annie_wang 已提交
2006
| properties | {[key:string]: Object} | No   | Authenticator properties.     |
A
Annie_wang 已提交
2007
| parameters | {[key:string]: Object} | No   | Customized parameters.|
A
annie_wangli 已提交
2008 2009 2010 2011 2012

## Constants<sup>8+</sup>

Enumerates the constants.

A
annie_wangli 已提交
2013 2014
**System capability**: SystemCapability.Account.AppAccount

A
Annie_wang 已提交
2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
| Name                           | Default Value                   | Description           |
| ----------------------------- | ---------------------- | ------------- |
| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation of adding an account implicitly. |
| ACTION_AUTHENTICATE           | "authenticate"         | Authentication operation.     |
| KEY_NAME                      | "name"                 | App account name. |
| KEY_OWNER                     | "owner"                | Owner of an app account.|
| KEY_TOKEN                     | "token"                | Token.     |
| KEY_ACTION                    | "action"               | Operation.     |
| KEY_AUTH_TYPE                 | "authType"             | Authentication type.   |
| KEY_SESSION_ID                | "sessionId"            | Session ID.   |
| KEY_CALLER_PID                | "callerPid"            | PID of the caller. |
| KEY_CALLER_UID                | "callerUid"            | UID of the caller. |
| KEY_CALLER_BUNDLE_NAME        | "callerBundleName"     | Bundle name of the caller.  |
| KEY_REQUIRED_LABELS           | "requiredLabels"       | Required labels.  |
| KEY_BOOLEAN_RESULT           | "booleanResult"         | Return value of the Boolean type.  |
A
annie_wangli 已提交
2030 2031 2032 2033 2034

## ResultCode<sup>8+</sup>

Enumerates the result codes.

A
annie_wangli 已提交
2035 2036
**System capability**: SystemCapability.Account.AppAccount

A
Annie_wang 已提交
2037 2038 2039 2040
| Name                                 | Default Value  | Description          |
| ----------------------------------- | ----- | ------------ |
| SUCCESS                             | 0     | The operation is successful.     |
| ERROR_ACCOUNT_NOT_EXIST             | 10001 | The app account does not exist.  |
A
Annie_wang 已提交
2041
| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. |
A
Annie_wang 已提交
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057
| ERROR_INVALID_PASSWORD              | 10003 | The password is invalid.     |
| ERROR_INVALID_REQUEST               | 10004 | The request is invalid.     |
| ERROR_INVALID_RESPONSE              | 10005 | The response is invalid.     |
| ERROR_NETWORK_EXCEPTION             | 10006 | The network is abnormal.     |
| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist.   |
| ERROR_OAUTH_CANCELED                | 10008 | The authentication is canceled.     |
| ERROR_OAUTH_LIST_TOO_LARGE          | 10009 | The size of the OAuth list exceeds the limit. |
| ERROR_OAUTH_SERVICE_BUSY            | 10010 | The OAuth service is busy. |
| ERROR_OAUTH_SERVICE_EXCEPTION       | 10011 | The OAuth service is abnormal. |
| ERROR_OAUTH_SESSION_NOT_EXIST       | 10012 | The session to be authenticated does not exist.  |
| ERROR_OAUTH_TIMEOUT                 | 10013 | The authentication timed out.     |
| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | The OAuth token does not exist.|
| ERROR_OAUTH_TOKEN_TOO_MANY          | 10015 | The number of OAuth tokens reaches the limit. |
| ERROR_OAUTH_UNSUPPORT_ACTION        | 10016 | The authentication operation is not supported. |
| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE     | 10017 | The authentication type is not supported. |
| ERROR_PERMISSION_DENIED             | 10018 | The required permission is missing.     |
A
annie_wangli 已提交
2058 2059 2060

## AuthenticatorCallback<sup>8+</sup>

A
Annie_wang 已提交
2061
Provides OAuth authenticator callbacks.
A
annie_wangli 已提交
2062 2063 2064

### onResult<sup>8+</sup>

A
annie_wangli 已提交
2065
onResult: (code: number, result: {[key: string]: any}) =&gt; void
A
annie_wangli 已提交
2066

A
Annie_wang 已提交
2067
Called to return the result of an authentication request.
A
annie_wangli 已提交
2068

A
annie_wangli 已提交
2069 2070 2071
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2072 2073 2074 2075
| Name   | Type                  | Mandatory  | Description    |
| ------ | -------------------- | ---- | ------ |
| code   | number               | Yes   | Authentication result code.|
| result | {[key: string]: any} | Yes   | Authentication result. |
A
annie_wangli 已提交
2076

A
annie_wangli 已提交
2077
**Example**
A
annie_wangli 已提交
2078

Z
zhangalong 已提交
2079
  ```js
A
annie_wangli 已提交
2080 2081 2082
  const appAccountManager = account_appAccount.createAppAccountManager();
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
A
annie_wangli 已提交
2083 2084 2085 2086 2087
      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
                    [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "readAge",
                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
      callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
2088 2089 2090 2091 2092 2093 2094
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

### onRequestRedirected<sup>8+</sup>

A
annie_wangli 已提交
2095
onRequestRedirected: (request: Want) =&gt; void
A
annie_wangli 已提交
2096

A
Annie_wang 已提交
2097
Called to redirect a request.
A
annie_wangli 已提交
2098

A
annie_wangli 已提交
2099
**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
2100

A
annie_wangli 已提交
2101
**Parameters**
A
Annie_wang 已提交
2102 2103 2104
| Name    | Type  | Mandatory  | Description        |
| ------- | ---- | ---- | ---------- |
| request | Want | Yes   | Request to be redirected.|
A
annie_wangli 已提交
2105 2106

**Example**
A
annie_wangli 已提交
2107

Z
zhangalong 已提交
2108
  ```js
A
annie_wangli 已提交
2109 2110 2111 2112 2113 2114 2115
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
              bundleName: "com.example.ohos.accountjsdemo",
              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
          });
      }
A
annie_wangli 已提交
2116

A
annie_wangli 已提交
2117
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
2118 2119 2120 2121
          var result = {[account_appAccount.Constants.KEY_NAME]: name,
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
2122 2123 2124 2125
      }
  }
  ```

A
Annie_wang 已提交
2126 2127 2128 2129
### onRequestContinued<sup>9+</sup>

onRequestContinued: () =&gt; void

A
Annie_wang 已提交
2130
Called to continue to process the request.
A
Annie_wang 已提交
2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145

**System capability**: SystemCapability.Account.AppAccount

**Example**

  ```js
  const appAccountManager = account_appAccount.createAppAccountManager();
  var sessionId = "1234";
  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
      callback.OnRequestContinued();
  }).catch((err) => {
      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
  });
  ```

A
annie_wangli 已提交
2146 2147
## Authenticator<sup>8+</sup>

A
Annie_wang 已提交
2148
Provides APIs to operate the authenticator.
A
annie_wangli 已提交
2149 2150 2151

### addAccountImplicitly<sup>8+</sup>

A
annie_wangli 已提交
2152
addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
2153

A
Annie_wang 已提交
2154
Implicitly adds an app account based on the specified authentication type and options. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2155

A
annie_wangli 已提交
2156 2157 2158
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2159 2160 2161 2162 2163
| 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.     |
A
Annie_wang 已提交
2164
| callback         | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the authentication result.|
A
annie_wangli 已提交
2165 2166 2167

### authenticate<sup>8+</sup>

A
annie_wangli 已提交
2168
authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
A
annie_wangli 已提交
2169

A
Annie_wang 已提交
2170
Authenticates an app account to obtain the OAuth access token. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
2171

A
annie_wangli 已提交
2172 2173 2174
**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2175 2176 2177 2178 2179 2180
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| name             | string                | Yes   | Name of the target app account.       |
| authType         | string                | Yes   | Authentication type.     |
| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
A
Annie_wang 已提交
2181
| callback         | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the authentication result.|
A
Annie_wang 已提交
2182 2183 2184 2185 2186

### verifyCredential<sup>9+</sup>

verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): void;

A
Annie_wang 已提交
2187
Verifies the credential of an app account. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
2188 2189 2190 2191

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2192 2193
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
2194
| name      | string                   | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
2195
| options   | [VerifyCredentialOptions](#verifycredentialoptions9)  | Yes   | Options for credential verification.           |
A
Annie_wang 已提交
2196
| callback  | [AuthenticatorCallback](#authenticatorcallback8)    | Yes   | Authenticator callback invoked to return the verification result.|
A
Annie_wang 已提交
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206

### setProperties<sup>9+</sup>

setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback): void;

Sets authenticator properties. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2207 2208 2209 2210
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
| options   | [SetPropertiesOptions](#setpropertiesoptions9)  | Yes   | Authenticator properties to set.           |
| callback  | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
2211 2212 2213 2214 2215 2216 2217 2218 2219 2220

### checkAccountLabels<sup>9+</sup>

checkAccountLabels(name: string, labels: Array&lt;string&gt;, callback: AuthenticatorCallback): void;

Checks the account labels. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2221 2222
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
2223
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
2224 2225
| labels    | Array&lt;string&gt;          | Yes   | Labels to check.                  |
| callback  | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the check result.|
A
Annie_wang 已提交
2226 2227 2228 2229 2230 2231 2232 2233 2234 2235

### isAccountRemovable<sup>9+</sup>

isAccountRemovable(name: string, callback: AuthenticatorCallback): void;

Checks whether an app account can be deleted. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Account.AppAccount

**Parameters**
A
Annie_wang 已提交
2236 2237
| Name             | Type                   | Mandatory  | Description             |
| ---------------- | --------------------- | ---- | --------------- |
A
Annie_wang 已提交
2238
| name      | string                | Yes   | Name of the target app account.             |
A
Annie_wang 已提交
2239
| callback  | [AuthenticatorCallback](#authenticatorcallback8) | Yes   | Authenticator callback invoked to return the result.|
A
Annie_wang 已提交
2240 2241 2242 2243 2244 2245 2246 2247

### getRemoteObject<sup>9+</sup>

getRemoteObject(): rpc.RemoteObject;

Obtains the remote object of an authenticator. This API cannot be overloaded.

**System capability**: SystemCapability.Account.AppAccount
A
annie_wangli 已提交
2248

A
annie_wangli 已提交
2249
**Example**
A
annie_wangli 已提交
2250

Z
zhangalong 已提交
2251
  ```js
A
annie_wangli 已提交
2252 2253 2254 2255 2256 2257 2258
  class MyAuthenticator extends account_appAccount.Authenticator {
      addAccountImplicitly(authType, callerBundleName, options, callback) {
          callback.onRequestRedirected({
              bundleName: "com.example.ohos.accountjsdemo",
              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
          });
      }
A
annie_wangli 已提交
2259

A
annie_wangli 已提交
2260
      authenticate(name, authType, callerBundleName, options, callback) {
A
annie_wangli 已提交
2261 2262 2263 2264
          var result = {[account_appAccount.Constants.KEY_NAME]: name,
                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
A
annie_wangli 已提交
2265
      }
A
Annie_wang 已提交
2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280

      verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback) {
          callback.onRequestRedirected({
              bundleName: "com.example.ohos.accountjsdemo",
              abilityName: "com.example.ohos.accountjsdemo.VerifyAbility",
              parameters: {
                name: name
              }
          });
      }

      setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback) {
          callback.onResult(account_appAccount.ResultCode.SUCCESS, {});
      }

A
Annie_wang 已提交
2281
      checkAccountLabels(name: string, labels: Array<string>, callback: AuthenticatorCallback) {
A
Annie_wang 已提交
2282 2283 2284 2285 2286 2287 2288 2289
          var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
      }
    
      isAccountRemovable(name, callback) {
          var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true};
          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
      }
A
annie_wangli 已提交
2290
  }
A
Annie_wang 已提交
2291
  var authenticator = null;
A
annie_wangli 已提交
2292 2293
  export default {
      onConnect(want) {
A
Annie_wang 已提交
2294 2295
          authenticator = new MyAuthenticator();
          return authenticator.getRemoteObject();
A
annie_wangli 已提交
2296 2297
      }
  }
A
Annie_wang 已提交
2298
  ```