1# @ohos.account.appAccount (App Account Management) 2 3The **appAccount** module provides APIs for adding, deleting, modifying, and querying app account information, and supports inter-app authentication and distributed data synchronization. 4 5> **NOTE** 6> 7> 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. 8 9 10## Modules to Import 11 12```js 13import account_appAccount from '@ohos.account.appAccount'; 14``` 15 16 17## account_appAccount.createAppAccountManager 18 19createAppAccountManager(): AppAccountManager 20 21Creates an **AppAccountManager** object. 22 23**System capability**: SystemCapability.Account.AppAccount 24 25**Return value** 26 27| Type | Description | 28| ----------------- | ------------ | 29| AppAccountManager | **AppAccountManager** object created.| 30 31**Example** 32 ```js 33 let appAccountManager = account_appAccount.createAppAccountManager(); 34 ``` 35 36## AppAccountManager 37 38Implements app account management. 39 40### createAccount<sup>9+</sup> 41 42createAccount(name: string, callback: AsyncCallback<void>): void; 43 44Creates an app account. This API uses an asynchronous callback to return the result. 45 46**System capability**: SystemCapability.Account.AppAccount 47 48**Parameters** 49 50| Name | Type | Mandatory | Description | 51| -------- | ------------------------- | ----- | -------------------- | 52| name | string | Yes | Name of the app account to create. | 53| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 54 55**Error codes** 56 57| ID| Error Message| 58| ------- | ------- | 59| 12300001 | System service exception. | 60| 12300002 | Invalid name. | 61| 12300004 | Account already exists. | 62| 12300007 | The number of accounts reaches the upper limit. | 63 64**Example** 65 66 ```js 67 try { 68 appAccountManager.createAccount("WangWu", (err) => { 69 console.log("createAccount err: " + JSON.stringify(err)); 70 }); 71 } catch (err) { 72 console.log("createAccount err: " + JSON.stringify(err)); 73 } 74 ``` 75 76### createAccount<sup>9+</sup> 77 78createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void 79 80Creates an app account with custom data. This API uses an asynchronous callback to return the result. 81 82**System capability**: SystemCapability.Account.AppAccount 83 84**Parameters** 85 86| Name | Type | Mandatory | Description | 87| --------- | ------------------------- | ---- | ---------------------------------------- | 88| name | string | Yes | Name of the app account to create. | 89| options | [CreateAccountOptions](#createaccountoptions9) | Yes | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens).| 90| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 91 92**Error codes** 93 94| ID| Error Message| 95| ------- | ------- | 96| 12300001 | System service exception. | 97| 12300002 | Invalid name or options. | 98| 12300004 | Account already exists. | 99| 12300007 | The number of accounts reaches the upper limit. | 100 101**Example** 102 103 ```js 104 let options = { 105 customData: { 106 "age": "10" 107 } 108 } 109 try { 110 appAccountManager.createAccount("LiSi", options, (err) => { 111 if (err) { 112 console.log("createAccount failed, error: " + JSON.stringify(err)); 113 } else { 114 console.log("createAccount successfully"); 115 } 116 }); 117 } catch(err) { 118 console.log("createAccount exception: " + JSON.stringify(err)); 119 } 120 ``` 121 122### createAccount<sup>9+</sup> 123 124createAccount(name: string, options?: CreateAccountOptions): Promise<void> 125 126Creates an app account with custom data. This API uses a promise to return the result. 127 128**System capability**: SystemCapability.Account.AppAccount 129 130**Parameters** 131 132| Name | Type | Mandatory | Description | 133| --------- | ------ | ---- | ---------------------------------------- | 134| name | string | Yes | Name of the app account to create. | 135| options | [CreateAccountOptions](#createaccountoptions9) | No | Options for creating the app account. You can customize data based on service requirements, but do not add sensitive data (such as passwords and tokens). This parameter can be left empty.| 136 137**Return value** 138 139| Type | Description | 140| ------------------- | --------------------- | 141| Promise<void> | Promise that returns no value.| 142 143**Error codes** 144 145| ID| Error Message| 146| ------- | -------| 147| 12300001 | System service exception. | 148| 12300002 | Invalid name or options. | 149| 12300004 | Account already exists. | 150| 12300007 | The number of accounts reaches the upper limit. | 151| 12400003 | The number of custom data reaches the upper limit. | 152 153**Example** 154 155 ```js 156 let options = { 157 customData: { 158 "age": "10" 159 } 160 } 161 try { 162 appAccountManager.createAccount("LiSi", options).then(() => { 163 console.log("createAccount successfully"); 164 }).catch((err) => { 165 console.log("createAccount failed, error: " + JSON.stringify(err)); 166 }); 167 } catch(err) { 168 console.log("createAccount exception: " + JSON.stringify(err)); 169 } 170 ``` 171 172### createAccountImplicitly<sup>9+</sup> 173 174createAccountImplicitly(owner: string, callback: AuthCallback): void 175 176Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. 177 178**System capability**: SystemCapability.Account.AppAccount 179 180**Parameters** 181 182| Name | Type | Mandatory | Description | 183| -------- | --------------------- | ---- | ----------------------- | 184| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 185| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result.| 186 187**Error codes** 188 189| ID| Error Message| 190| ------- | -------| 191| 12300001 | System service exception. | 192| 12300002 | Invalid owner. | 193| 12300007 | The number of accounts reaches the upper limit. | 194| 12300010 | Account service busy. | 195| 12300113 | Authenticator service not found. | 196| 12300114 | Authenticator service exception. | 197 198**Example** 199 200 ```js 201 function onResultCallback(code, result) { 202 console.log("resultCode: " + code); 203 console.log("result: " + JSON.stringify(result)); 204 } 205 206 function onRequestRedirectedCallback(request) { 207 let wantInfo = { 208 deviceId: '', 209 bundleName: 'com.example.accountjsdemo', 210 action: 'ohos.want.action.viewData', 211 entities: ['entity.system.default'], 212 } 213 this.context.startAbility(wantInfo).then(() => { 214 console.log("startAbility successfully"); 215 }).catch((err) => { 216 console.log("startAbility err: " + JSON.stringify(err)); 217 }) 218 } 219 220 try { 221 appAccountManager.createAccountImplicitly("com.example.accountjsdemo", { 222 onResult: onResultCallback, 223 onRequestRedirected: onRequestRedirectedCallback 224 }); 225 } catch (err) { 226 console.log("createAccountImplicitly exception: " + JSON.stringify(err)); 227 } 228 ``` 229 230### createAccountImplicitly<sup>9+</sup> 231 232createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 233 234Creates an app account implicitly based on the specified account owner and options. This API uses an asynchronous callback to return the result. 235 236**System capability**: SystemCapability.Account.AppAccount 237 238**Parameters** 239 240| Name | Type | Mandatory | Description | 241| -------- | --------------------- | ---- | ----------------------- | 242| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 243| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating the account. | 244| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback used to return the result. | 245 246**Error codes** 247 248| ID| Error Message| 249| ------- | ------- | 250| 12300001 | System service exception. | 251| 12300002 | Invalid name or options. | 252| 12300007 | The number of accounts reaches the upper limit. | 253| 12300010 | Account service busy. | 254| 12300113 | Authenticator service not found. | 255| 12300114 | Authenticator service exception. | 256 257**Example** 258 259 ```js 260 function onResultCallback(code, result) { 261 console.log("resultCode: " + code); 262 console.log("result: " + JSON.stringify(result)); 263 } 264 265 function onRequestRedirectedCallback(request) { 266 let wantInfo = { 267 deviceId: '', 268 bundleName: 'com.example.accountjsdemo', 269 action: 'ohos.want.action.viewData', 270 entities: ['entity.system.default'], 271 } 272 this.context.startAbility(wantInfo).then(() => { 273 console.log("startAbility successfully"); 274 }).catch((err) => { 275 console.log("startAbility err: " + JSON.stringify(err)); 276 }) 277 } 278 279 let options = { 280 authType: "getSocialData", 281 requiredLabels: [ "student" ] 282 }; 283 try { 284 appAccountManager.createAccountImplicitly("com.example.accountjsdemo", options, { 285 onResult: onResultCallback, 286 onRequestRedirected: onRequestRedirectedCallback 287 }); 288 } catch (err) { 289 console.log("createAccountImplicitly exception: " + JSON.stringify(err)); 290 } 291 ``` 292 293### removeAccount<sup>9+</sup> 294 295removeAccount(name: string, callback: AsyncCallback<void>): void 296 297Removes an app account. This API uses an asynchronous callback to return the result. 298 299**System capability**: SystemCapability.Account.AppAccount 300 301**Parameters** 302 303| Name | Type | Mandatory | Description | 304| -------- | ------------------------- | ---- | ---------------- | 305| name | string | Yes | Name of the app account to remove. | 306| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 307 308**Error codes** 309 310| ID| Error Message| 311| ------- | ------- | 312| 12300001 | System service exception. | 313| 12300002 | Invalid name. | 314| 12300003 | Account not found. | 315 316**Example** 317 318 ```js 319 try { 320 appAccountManager.removeAccount("ZhaoLiu", (err) => { 321 if (err) { 322 console.log("removeAccount failed, error: " + JSON.stringify(err)); 323 } else { 324 console.log("removeAccount successfully"); 325 } 326 }); 327 } catch(err) { 328 console.log("removeAccount exception: " + JSON.stringify(err)); 329 } 330 ``` 331 332### removeAccount<sup>9+</sup> 333 334removeAccount(name: string): Promise<void> 335 336Removes an app account. This API uses a promise to return the result. 337 338**System capability**: SystemCapability.Account.AppAccount 339 340**Parameters** 341 342| Name | Type | Mandatory | Description | 343| ---- | ------ | ---- | ----------- | 344| name | string | Yes | Name of the app account to remove.| 345 346**Return value** 347 348| Type | Description | 349| :------------------ | :-------------------- | 350| Promise<void> | Promise that returns no value.| 351 352**Error codes** 353 354| ID| Error Message| 355| ------- | ------- | 356| 12300001 | System service exception. | 357| 12300002 | Invalid name. | 358| 12300003 | Account not found. | 359 360**Example** 361 362 ```js 363 try { 364 appAccountManager.removeAccount("Lisi").then(() => { 365 console.log("removeAccount successfully"); 366 }).catch((err) => { 367 console.log("removeAccount failed, error: " + JSON.stringify(err)); 368 }); 369 } catch (err) { 370 console.log("removeAccount exception: " + JSON.stringify(err)); 371 } 372 ``` 373 374### setAppAccess<sup>9+</sup> 375 376setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void 377 378Sets the access to the data of an account for an app. This API uses an asynchronous callback to return the result. 379 380**System capability**: SystemCapability.Account.AppAccount 381 382**Parameters** 383 384| Name | Type | Mandatory | Description | 385| ------------ | ------------------------- | ---- | --------------------------------- | 386| name | string | Yes | Name of the target app account. | 387| bundleName | string | Yes | Bundle name of the app. | 388| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| 389| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 390 391**Error codes** 392 393| ID| Error Message| 394| ------- | -------| 395| 12300001 | System service exception. | 396| 12300002 | Invalid name or bundleName. | 397| 12300003 | Account not found. | 398| 12400001 | Application not found. | 399 400**Example** 401 402 ```js 403 try { 404 appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true, (err) => { 405 if (err) { 406 console.log("setAppAccess failed: " + JSON.stringify(err)); 407 } else { 408 console.log("setAppAccess successfully"); 409 } 410 }); 411 } catch (err) { 412 console.log("setAppAccess exception: " + JSON.stringify(err)); 413 } 414 ``` 415 416### setAppAccess<sup>9+</sup> 417 418setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void> 419 420Sets the access to the data of an account for an app. This API uses a promise to return the result. 421 422**System capability**: SystemCapability.Account.AppAccount 423 424**Parameters** 425 426| Name | Type | Mandatory | Description | 427| ---------- | ------ | ---- | --------- | 428| name | string | Yes | Name of the target app account. | 429| bundleName | string | Yes | Bundle name of the app.| 430| isAccessible | boolean | Yes | Whether the access is allowed. The value **true** means to allow the access; the value **false** means the opposite.| 431 432**Return value** 433 434| Type | Description | 435| :------------------ | :-------------------- | 436| Promise<void> | Promise that returns no value.| 437 438**Error codes** 439 440| ID| Error Message| 441| ------- | -------| 442| 12300001 | System service exception. | 443| 12300002 | Invalid name or bundleName. | 444| 12300003 | Account not found. | 445| 12400001 | Application not found. | 446 447**Example** 448 449 ```js 450 try { 451 appAccountManager.setAppAccess("ZhangSan", "com.example.accountjsdemo", true).then(() => { 452 console.log("setAppAccess successfully"); 453 }).catch((err) => { 454 console.log("setAppAccess failed: " + JSON.stringify(err)); 455 }); 456 } catch (err) { 457 console.log("setAppAccess exception: " + JSON.stringify(err)); 458 } 459 ``` 460 461### checkAppAccess<sup>9+</sup> 462 463checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void 464 465Checks whether an app can access the data of an account. This API uses an asynchronous callback to return the result. 466 467**System capability**: SystemCapability.Account.AppAccount 468 469**Parameters** 470 471| Name | Type | Mandatory | Description | 472| ---------- | ------------------------- | ---- | --------------------------------- | 473| name | string | Yes | Name of the target app account. | 474| bundleName | string | Yes | Bundle name of the app. | 475| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.| 476 477**Error codes** 478 479| ID| Error Message| 480| ------- | ------- | 481| 12300001 | System service exception. | 482| 12300002 | Invalid name or bundleName. | 483| 12300003 | Account not found. | 484| 12400001 | Application not found. | 485 486**Example** 487 488 ```js 489 try { 490 appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo", (err, isAccessible) => { 491 if (err) { 492 console.log("checkAppAccess failed, error: " + JSON.stringify(err)); 493 } else { 494 console.log("checkAppAccess successfully"); 495 } 496 }); 497 } catch (err) { 498 console.log("checkAppAccess exception: " + JSON.stringify(err)); 499 } 500 ``` 501 502### checkAppAccess<sup>9+</sup> 503 504checkAppAccess(name: string, bundleName: string): Promise<boolean> 505 506Checks whether an app can access the data of an account. This API uses a promise to return the result. 507 508**System capability**: SystemCapability.Account.AppAccount 509 510**Parameters** 511 512| Name | Type | Mandatory | Description | 513| ---------- | ------ | ---- | --------- | 514| name | string | Yes | Name of the target app account. | 515| bundleName | string | Yes | Bundle name of the app.| 516 517**Return value** 518 519| Type | Description | 520| ------------------- | --------------------- | 521| Promise<boolean> | Promise used to return the result. The value **true** means the app can access the account data; the value **false** means the opposite.| 522 523**Error codes** 524 525| ID| Error Message| 526| ------- | -------| 527| 12300001 | System service exception. | 528| 12300002 | Invalid name or bundleName. | 529| 12300003 | Account not found. | 530| 12400001 | Application not found. | 531 532**Example** 533 534 ```js 535 try { 536 appAccountManager.checkAppAccess("ZhangSan", "com.example.accountjsdemo").then((isAccessible) => { 537 console.log("checkAppAccess successfully, isAccessible: " + isAccessible); 538 }).catch((err) => { 539 console.log("checkAppAccess failed, error: " + JSON.stringify(err)); 540 }); 541 } catch (err) { 542 console.log("checkAppAccess exception: " + JSON.stringify(err)); 543 } 544 ``` 545 546### setDataSyncEnabled<sup>9+</sup> 547 548setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void 549 550Sets data synchronization for an app account. This API uses an asynchronous callback to return the result. 551 552**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 553 554**System capability**: SystemCapability.Account.AppAccount 555 556**Parameters** 557 558| Name | Type | Mandatory | Description | 559| -------- | ------------------------- | ---- | ------------------------- | 560| name | string | Yes | Name of the target app account. | 561| isEnabled | boolean | Yes | Whether to enable data synchronization. | 562| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 563 564**Error codes** 565 566| ID| Error Message| 567| ------- | -------| 568| 12300001 | System service exception. | 569| 12300002 | Invalid name. | 570| 12300003 | Account not found. | 571 572**Example** 573 574 ```js 575 try { 576 appAccountManager.setDataSyncEnabled("ZhangSan", true, (err) => { 577 console.log("setDataSyncEnabled err: " + JSON.stringify(err)); 578 }); 579 } catch (err) { 580 console.log("setDataSyncEnabled err: " + JSON.stringify(err)); 581 } 582 ``` 583 584### setDataSyncEnabled<sup>9+</sup> 585 586setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void> 587 588Sets data synchronization for an app account. This API uses a promise to return the result. 589 590**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 591 592**System capability**: SystemCapability.Account.AppAccount 593 594**Parameters** 595 596| Name | Type | Mandatory | Description | 597| -------- | ------- | ---- | ----------- | 598| name | string | Yes | Name of the target app account. | 599| isEnabled | boolean | Yes | Whether to enable data synchronization.| 600 601**Return value** 602 603| Type | Description | 604| :------------------ | :-------------------- | 605| Promise<void> | Promise that returns no value.| 606 607**Error codes** 608 609| ID| Error Message| 610| ------- | ------- | 611| 12300001 | System service exception. | 612| 12300002 | Invalid name. | 613| 12300003 | Account not found. | 614 615**Example** 616 617 ```js 618 try { 619 appAccountManager .setDataSyncEnabled("ZhangSan", true).then(() => { 620 console.log('setDataSyncEnabled Success'); 621 }).catch((err) => { 622 console.log("setDataSyncEnabled err: " + JSON.stringify(err)); 623 }); 624 } catch (err) { 625 console.log("setDataSyncEnabled err: " + JSON.stringify(err)); 626 } 627 ``` 628 629### checkDataSyncEnabled<sup>9+</sup> 630 631checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void 632 633Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result. 634 635**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 636 637**System capability**: SystemCapability.Account.AppAccount 638 639**Parameters** 640 641| Name | Type | Mandatory | Description | 642| -------- | ---------------------------- | ---- | --------------------- | 643| name | string | Yes | Name of the target app account. | 644| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| 645 646**Error codes** 647 648| ID| Error Message| 649| ------- | ------- | 650| 12300001 | System service exception. | 651| 12300002 | Invalid name. | 652| 12300003 | Account not found. | 653 654**Example** 655 656 ```js 657 try { 658 appAccountManager.checkDataSyncEnabled("ZhangSan", (err, isEnabled) => { 659 if (err) { 660 console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err)); 661 } else { 662 console.log('checkDataSyncEnabled successfully, isEnabled: ' + isEnabled); 663 } 664 }); 665 } catch (err) { 666 console.log("checkDataSyncEnabled err: " + JSON.stringify(err)); 667 } 668 ``` 669 670### checkDataSyncEnabled<sup>9+</sup> 671 672checkDataSyncEnabled(name: string): Promise<boolean> 673 674Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result. 675 676**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 677 678**System capability**: SystemCapability.Account.AppAccount 679 680**Parameters** 681 682| Name | Type | Mandatory | Description | 683| ---- | ------ | ---- | ------- | 684| name | string | Yes | Name of the target app account.| 685 686**Return value** 687 688| Type | Description | 689| :--------------------- | :-------------------- | 690| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| 691 692**Error codes** 693 694| ID| Error Message| 695| ------- | -------| 696| 12300001 | System service exception. | 697| 12300002 | Invalid name. | 698| 12300003 | Account not found. | 699 700**Example** 701 702 ```js 703 try { 704 appAccountManager.checkDataSyncEnabled("ZhangSan").then((isEnabled) => { 705 console.log("checkDataSyncEnabled successfully, isEnabled: " + isEnabled); 706 }).catch((err) => { 707 console.log("checkDataSyncEnabled failed, err: " + JSON.stringify(err)); 708 }); 709 } catch (err) { 710 console.log("checkDataSyncEnabled err: " + JSON.stringify(err)); 711 } 712 ``` 713 714### setCredential<sup>9+</sup> 715 716setCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void 717 718Sets a credential for an app account. This API uses an asynchronous callback to return the result. 719 720**System capability**: SystemCapability.Account.AppAccount 721 722**Parameters** 723 724| Name | Type | Mandatory | Description | 725| -------------- | ------------------------- | ---- | ------------- | 726| name | string | Yes | Name of the target app account. | 727| credentialType | string | Yes | Type of the credential to set. | 728| credential | string | Yes | Credential value. | 729| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the credential is set successfully, **err** is **null**. Otherwise, **err** is an error object.| 730 731**Error codes** 732 733| ID| Error Message| 734| ------- | -------| 735| 12300001 | System service exception. | 736| 12300002 | Invalid name or credentialType or credential. | 737| 12300003 | Account not found. | 738 739**Example** 740 741 ```js 742 try { 743 appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx", (err) => { 744 if (err) { 745 console.log("setCredential failed, error: " + JSON.stringify(err)); 746 } else { 747 console.log("setCredential successfully"); 748 } 749 }); 750 } catch (err) { 751 console.log("setCredential exception: " + JSON.stringify(err)); 752 } 753 ``` 754 755### setCredential<sup>9+</sup> 756 757setCredential(name: string, credentialType: string, credential: string): Promise<void> 758 759Sets a credential for an app account. This API uses a promise to return the result. 760 761**System capability**: SystemCapability.Account.AppAccount 762 763**Parameters** 764 765| Name | Type | Mandatory | Description | 766| -------------- | ------ | ---- | ---------- | 767| name | string | Yes | Name of the target app account. | 768| credentialType | string | Yes | Type of the credential to set.| 769| credential | string | Yes | Credential value. | 770 771**Return value** 772 773| Type | Description | 774| :------------------ | :-------------------- | 775| Promise<void> | Promise that returns no value.| 776 777**Error codes** 778 779| ID| Error Message| 780| ------- | -------| 781| 12300001 | System service exception. | 782| 12300002 | Invalid name or credentialType or credential. | 783| 12300003 | Account not found. | 784 785**Example** 786 787 ```js 788 try { 789 appAccountManager.setCredential("ZhangSan", "PIN_SIX", "xxxxxx").then(() => { 790 console.log("setCredential successfully"); 791 }).catch((err) => { 792 console.log("setCredential failed, error: " + JSON.stringify(err)); 793 }); 794 } catch (err) { 795 console.log("setCredential exception: " + JSON.stringify(err)); 796 } 797 ``` 798 799### getCredential<sup>9+</sup> 800 801getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 802 803Obtains the credential of an app account. This API uses an asynchronous callback to return the result. 804 805**System capability**: SystemCapability.Account.AppAccount 806 807**Parameters** 808 809| Name | Type | Mandatory | Description | 810| -------------- | --------------------------- | ---- | -------------- | 811| name | string | Yes | Name of the target app account. | 812| credentialType | string | Yes | Type of the credential to obtain.| 813| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| 814 815**Error codes** 816 817| ID| Error Message| 818| ------- | ------- | 819| 12300001 | System service exception. | 820| 12300002 | Invalid name or credentialType. | 821| 12300003 | Account not found. | 822| 12300102 | Credential not found. | 823 824**Example** 825 826 ```js 827 try { 828 appAccountManager.getCredential("ZhangSan", "PIN_SIX", (err, result) => { 829 if (err) { 830 console.log("getCredential failed, error: " + JSON.stringify(err)); 831 } else { 832 console.log('getCredential successfully, result: ' + result); 833 } 834 }); 835 } catch (err) { 836 console.log("getCredential err: " + JSON.stringify(err)); 837 } 838 ``` 839 840### getCredential<sup>9+</sup> 841 842getCredential(name: string, credentialType: string): Promise<string> 843 844Obtains the credential of an app account. This API uses a promise to return the result. 845 846**System capability**: SystemCapability.Account.AppAccount 847 848**Parameters** 849 850| Name | Type | Mandatory | Description | 851| -------------- | ------ | ---- | ---------- | 852| name | string | Yes | Name of the target app account.| 853| credentialType | string | Yes | Type of the credential to obtain.| 854 855**Return value** 856 857| Type | Description | 858| :-------------------- | :-------------------- | 859| Promise<string> | Promise used to return the credential obtained.| 860 861**Error codes** 862 863| ID| Error Message| 864| ------- | ------- | 865| 12300001 | System service exception. | 866| 12300002 | Invalid name or credentialType. | 867| 12300003 | Account not found. | 868| 12300102 | Credential not found. | 869 870**Example** 871 872 ```js 873 try { 874 appAccountManager.getCredential("ZhangSan", "PIN_SIX").then((credential) => { 875 console.log("getCredential successfully, credential: " + credential); 876 }).catch((err) => { 877 console.log("getCredential failed, error: " + JSON.stringify(err)); 878 }); 879 } catch (err) { 880 console.log("getCredential exception: " + JSON.stringify(err)); 881 } 882 ``` 883 884### setCustomData<sup>9+</sup> 885 886setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void 887 888Sets custom data for an app account. This API uses an asynchronous callback to return the result. 889 890**System capability**: SystemCapability.Account.AppAccount 891 892**Parameters** 893 894| Name | Type | Mandatory | Description | 895| -------- | ------------------------- | ---- | ----------------- | 896| name | string | Yes | Name of the target app account.| 897| key | string | Yes | Key of the custom data to set.| 898| value | string | Yes | Value of the custom data to set.| 899| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 900 901**Error codes** 902 903| ID| Error Message| 904| ------- | -------| 905| 12300001 | System service exception. | 906| 12300002 | Invalid name or key or value. | 907| 12300003 | Account not found. | 908| 12400003 | The number of custom data reaches the upper limit. | 909 910**Example** 911 912 ```js 913 try { 914 appAccountManager.setCustomData("ZhangSan", "age", "12", (err) => { 915 if (err) { 916 console.log("setCustomData failed, error: " + JSON.stringify(err)); 917 } else { 918 console.log("setCustomData successfully"); 919 } 920 }); 921 } catch (err) { 922 console.log("setCustomData exception: " + JSON.stringify(err)); 923 } 924 ``` 925 926### setCustomData<sup>9+</sup> 927 928setCustomData(name: string, key: string, value: string): Promise<void> 929 930Sets custom data for an app account. This API uses a promise to return the result. 931 932**System capability**: SystemCapability.Account.AppAccount 933 934**Parameters** 935 936| Name | Type| Mandatory | Description | 937| ----- | ------ | ---- | ----------------- | 938| name | string | Yes | Name of the target app account. | 939| key | string | Yes | Key of the custom data to set.| 940| value | string | Yes | Value of the custom data to set.| 941 942**Return value** 943 944| Type | Description | 945| :------------------ | :-------------------- | 946| Promise<void> | Promise that returns no value.| 947 948**Error codes** 949 950| ID| Error Message| 951| ------- | -------| 952| 12300001 | System service exception. | 953| 12300002 | Invalid name or key or value. | 954| 12300003 | Account not found. | 955| 12400003 | The number of custom data reaches the upper limit. | 956 957**Example** 958 959 ```js 960 try { 961 appAccountManager.setCustomData("ZhangSan", "age", "12").then(() => { 962 console.log("setCustomData successfully"); 963 }).catch((err) => { 964 console.log("setCustomData failed, error: " + JSON.stringify(err)); 965 }); 966 } catch (err) { 967 console.log("setCustomData exception: " + JSON.stringify(err)); 968 } 969 ``` 970 971### getCustomData<sup>9+</sup> 972 973getCustomData(name: string, key: string, callback: AsyncCallback<string>): void 974 975Obtains the custom data of an app account based on the specified key. This API uses an asynchronous callback to return the result. 976 977**System capability**: SystemCapability.Account.AppAccount 978 979**Parameters** 980 981| Name | Type | Mandatory | Description | 982| -------- | --------------------------- | ----- | ------------------------ | 983| name | string | Yes | Name of the target app account. | 984| key | string | Yes | Key of the custom data to obtain. | 985| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the custom data value obtained. Otherwise, **err** is an error object.| 986 987**Error codes** 988 989| ID| Error Message| 990| ------- | -------| 991| 12300001 | System service exception. | 992| 12300002 | Invalid name or key. | 993| 12300003 | Account not found. | 994| 12400002 | Custom data not found. | 995 996**Example** 997 998 ```js 999 try { 1000 appAccountManager.getCustomData("ZhangSan", "age", (err, data) => { 1001 if (err) { 1002 console.log('getCustomData failed, error: ' + err); 1003 } else { 1004 console.log("getCustomData successfully, data: " + data); 1005 } 1006 }); 1007 } catch (err) { 1008 console.log("getCustomData exception: " + JSON.stringify(err)); 1009 } 1010 ``` 1011 1012### getCustomData<sup>9+</sup> 1013 1014getCustomData(name: string, key: string): Promise<string> 1015 1016Obtains the custom data of an app account based on the specified key. This API uses a promise to return the result. 1017 1018**System capability**: SystemCapability.Account.AppAccount 1019 1020**Parameters** 1021 1022| Name | Type | Mandatory | Description | 1023| ---- | ------ | ---- | --------- | 1024| name | string | Yes | Name of the target app account. | 1025| key | string | Yes | Key of the custom data to obtain.| 1026 1027**Return value** 1028 1029| Type | Description | 1030| --------------------- | --------------------- | 1031| Promise<string> | Promise used to return the custom data value obtained.| 1032 1033**Error codes** 1034 1035| ID| Error Message| 1036| ------- | -------| 1037| 12300001 | System service exception. | 1038| 12300002 | Invalid name or key. | 1039| 12300003 | Account not found. | 1040| 12400002 | Custom data not found. | 1041 1042**Example** 1043 1044 ```js 1045 try { 1046 appAccountManager.getCustomData("ZhangSan", "age").then((data) => { 1047 console.log("getCustomData successfully, data: " + data); 1048 }).catch((err) => { 1049 console.log("getCustomData failed, error: " + JSON.stringify(err)); 1050 }); 1051 } catch (err) { 1052 console.log("getCustomData exception: " + JSON.stringify(err)); 1053 } 1054 ``` 1055 1056### getCustomDataSync<sup>9+</sup> 1057 1058getCustomDataSync(name: string, key: string): string; 1059 1060Obtains the custom data of an app account based on the specified key. The API returns the result synchronously. 1061 1062**System capability**: SystemCapability.Account.AppAccount 1063 1064**Parameters** 1065 1066| Name | Type | Mandatory | Description | 1067| ---- | ------ | ---- | --------- | 1068| name | string | Yes | Name of the target app account. | 1069| key | string | Yes | Key of the custom data to obtain.| 1070 1071**Return value** 1072 1073| Type | Description | 1074| --------------------- | --------------------- | 1075| string | Value of the custom data obtained.| 1076 1077**Error codes** 1078 1079| ID| Error Message| 1080| ------- | -------| 1081| 12300001 | System service exception. | 1082| 12300002 | Invalid name or key. | 1083| 12300003 | Account not found. | 1084| 12400002 | Custom data not found. | 1085 1086**Example** 1087 1088 ```js 1089 try { 1090 let value = appAccountManager.getCustomDataSync("ZhangSan", "age"); 1091 console.info("getCustomDataSync successfully, vaue:" + value); 1092 } catch (err) { 1093 console.error("getCustomDataSync failed, error: " + JSON.stringify(err)); 1094 } 1095 ``` 1096 1097### getAllAccounts<sup>9+</sup> 1098 1099getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 1100 1101Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. 1102 1103**System capability**: SystemCapability.Account.AppAccount 1104 1105**Parameters** 1106 1107| Name | Type | Mandatory | Description | 1108| -------- | ---------------------------------------- | ---- | --------- | 1109| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.| 1110 1111**Error codes** 1112 1113| ID| Error Message| 1114| ------- | -------| 1115| 12300001 | System service exception. | 1116 1117**Example** 1118 1119 ```js 1120 try { 1121 appAccountManager.getAllAccounts((err, data) => { 1122 if (err) { 1123 console.debug("getAllAccounts failed, error:" + JSON.stringify(err)); 1124 } else { 1125 console.debug("getAllAccounts successfully"); 1126 } 1127 }); 1128 } catch (err) { 1129 console.debug("getAllAccounts exception: " + JSON.stringify(err)); 1130 } 1131 ``` 1132 1133### getAllAccounts<sup>9+</sup> 1134 1135getAllAccounts(): Promise<Array<AppAccountInfo>> 1136 1137Obtains information about all accessible app accounts. This API uses a promise to return the result. 1138 1139**System capability**: SystemCapability.Account.AppAccount 1140 1141**Return value** 1142 1143| Type | Description | 1144| ---------------------------------------- | --------------------- | 1145| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return information about all accessible accounts.| 1146 1147**Error codes** 1148 1149| ID| Error Message| 1150| ------- | -------| 1151| 12300001 | System service exception. | 1152 1153**Example** 1154 1155 ```js 1156 try { 1157 appAccountManager.getAllAccounts().then((data) => { 1158 console.debug("getAllAccounts successfully"); 1159 }).catch((err) => { 1160 console.debug("getAllAccounts failed, error:" + JSON.stringify(err)); 1161 }); 1162 } catch (err) { 1163 console.debug("getAllAccounts exception: " + JSON.stringify(err)); 1164 } 1165 ``` 1166 1167### getAccountsByOwner<sup>9+</sup> 1168 1169getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void 1170 1171Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result. 1172 1173**System capability**: SystemCapability.Account.AppAccount 1174 1175**Parameters** 1176 1177| Name | Type | Mandatory | Description | 1178| -------- | ---------------------------------------- | ---- | --------- | 1179| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1180| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is null and **data** is the app account information obtained. Otherwise, **err** is an error object.| 1181 1182**Error codes** 1183 1184| ID| Error Message| 1185| ------- | -------| 1186| 12300001 | System service exception. | 1187| 12300002 | Invalid owner. | 1188| 12400001 | Application not found. | 1189 1190**Example** 1191 1192 ```js 1193 try { 1194 appAccountManager.getAccountsByOwner("com.example.accountjsdemo2", (err, data) => { 1195 if (err) { 1196 console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err)); 1197 } else { 1198 console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data)); 1199 } 1200 }); 1201 } catch (err) { 1202 console.debug("getAccountsByOwner exception:" + JSON.stringify(err)); 1203 } 1204 ``` 1205 1206### getAccountsByOwner<sup>9+</sup> 1207 1208getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>> 1209 1210Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. 1211 1212**System capability**: SystemCapability.Account.AppAccount 1213 1214**Parameters** 1215 1216| Name | Type | Mandatory | Description | 1217| ----- | ------ | ---- | ------ | 1218| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 1219 1220**Return value** 1221 1222| Type | Description | 1223| ---------------------------------------- | --------------------- | 1224| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the app account information obtained.| 1225 1226**Error codes** 1227 1228| ID| Error Message| 1229| ------- | -------| 1230| 12300001 | System service exception. | 1231| 12300002 | Invalid owner. | 1232| 12400001 | Application not found. | 1233 1234**Example** 1235 1236 ```js 1237 try { 1238 appAccountManager.getAccountsByOwner("com.example.accountjsdemo2").then((data) => { 1239 console.debug("getAccountsByOwner successfully, data:" + JSON.stringify(data)); 1240 }).catch((err) => { 1241 console.debug("getAccountsByOwner failed, error:" + JSON.stringify(err)); 1242 }); 1243 } catch (err) { 1244 console.debug("getAccountsByOwner exception:" + JSON.stringify(err)); 1245 } 1246 ``` 1247 1248### on('accountChange')<sup>9+</sup> 1249 1250on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 1251 1252Subscribes to account information changes of apps. 1253 1254**System capability**: SystemCapability.Account.AppAccount 1255 1256**Parameters** 1257 1258| Name | Type | Mandatory | Description | 1259| -------- | ---------------------------------------- | ---- | ------------------------------ | 1260| type | 'accountChange' | Yes | Event type to subscribe to. The value is **'accountChange'**. An event will be reported when the account information of the target app changes.| 1261| owners | Array<string> | Yes | App bundle names of the account. | 1262| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return a list of app accounts whose information is changed. | 1263 1264**Error codes** 1265 1266| ID| Error Message| 1267| ------- | ------- | 1268| 12300001 | System service exception. | 1269| 12300002 | Invalid type or owners. | 1270| 12300011 | Callback has been registered. | 1271| 12400001 | Application not found. | 1272 1273**Example** 1274 1275 ```js 1276 function changeOnCallback(data){ 1277 console.log("receive change data:" + JSON.stringify(data)); 1278 } 1279 try{ 1280 appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback); 1281 } catch(err) { 1282 console.error("on accountChange failed, error:" + JSON.stringify(err)); 1283 } 1284 ``` 1285 1286### off('accountChange')<sup>9+</sup> 1287 1288off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void 1289 1290Unsubscribes from account information changes. 1291 1292**System capability**: SystemCapability.Account.AppAccount 1293 1294**Parameters** 1295 1296| Name | Type | Mandatory | Description | 1297| -------- | -------------------------------- | ---- | ------------ | 1298| type | 'accountChange' | Yes | Event type to unsubscribe from. The value is **'accountChange'**. | 1299| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | No | Callback to unregister.| 1300 1301**Error codes** 1302 1303| ID| Error Message| 1304| ------- | -------| 1305| 12300001 | System service exception. | 1306| 12300002 | Invalid type. | 1307| 12300012 | Callback has not been registered. | 1308 1309**Example** 1310 1311 ```js 1312 function changeOnCallback(data){ 1313 console.log("receive change data:" + JSON.stringify(data)); 1314 } 1315 try{ 1316 appAccountManager.on("accountChange", ["com.example.actsaccounttest"], changeOnCallback); 1317 } catch(err) { 1318 console.error("on accountChange failed, error:" + JSON.stringify(err)); 1319 } 1320 try{ 1321 appAccountManager.off('accountChange', changeOnCallback); 1322 } 1323 catch(err){ 1324 console.error("off accountChange failed, error:" + JSON.stringify(err)); 1325 } 1326 ``` 1327 1328### auth<sup>9+</sup> 1329 1330auth(name: string, owner: string, authType: string, callback: AuthCallback): void 1331 1332Authenticates an app account. This API uses an asynchronous callback to return the result. 1333 1334**System capability**: SystemCapability.Account.AppAccount 1335 1336**Parameters** 1337 1338| Name | Type | Mandatory | Description | 1339| -------- | --------------------- | ---- | --------------- | 1340| name | string | Yes | Name of the target app account. | 1341| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1342| authType | string | Yes | Authentication type. | 1343| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the authentication result.| 1344 1345**Error codes** 1346 1347| ID| Error Message| 1348| ------- | -------| 1349| 12300001 | System service exception. | 1350| 12300002 | Invalid name or owner or authType. | 1351| 12300003 | Account not found. | 1352| 12300010 | Account service busy. | 1353| 12300113 | Authenticator service not found. | 1354| 12300114 | Authenticator service exception. | 1355 1356**Example** 1357 1358 ```js 1359 1360 1361 function onResultCallback(code, authResult) { 1362 console.log("resultCode: " + code); 1363 console.log("authResult: " + JSON.stringify(authResult)); 1364 } 1365 1366 function onRequestRedirectedCallback(request) { 1367 let wantInfo = { 1368 deviceId: '', 1369 bundleName: 'com.example.accountjsdemo', 1370 action: 'ohos.want.action.viewData', 1371 entities: ['entity.system.default'], 1372 } 1373 this.context.startAbility(wantInfo).then(() => { 1374 console.log("startAbility successfully"); 1375 }).catch((err) => { 1376 console.log("startAbility err: " + JSON.stringify(err)); 1377 }) 1378 } 1379 1380 try { 1381 appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", { 1382 onResult: onResultCallback, 1383 onRequestRedirected: onRequestRedirectedCallback 1384 }); 1385 } catch (err) { 1386 console.log("auth exception: " + JSON.stringify(err)); 1387 } 1388 ``` 1389 1390### auth<sup>9+</sup> 1391 1392auth(name: string, owner: string, authType: string, options: {[key: string]: Object}, callback: AuthCallback): void 1393 1394Authenticates an app account with customized options. This API uses an asynchronous callback to return the result. 1395 1396**System capability**: SystemCapability.Account.AppAccount 1397 1398**Parameters** 1399 1400| Name | Type | Mandatory | Description | 1401| -------- | --------------------- | ---- | --------------- | 1402| name | string | Yes | Name of the target app account. | 1403| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1404| authType | string | Yes | Authentication type. | 1405| options | {[key: string]: Object} | Yes | Options for the authentication. | 1406| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the authentication result.| 1407 1408**Error codes** 1409 1410| ID| Error Message| 1411| ------- | -------| 1412| 12300001 | System service exception. | 1413| 12300002 | Invalid name or owner or authType. | 1414| 12300003 | Account not exist. | 1415| 12300010 | Account service busy. | 1416| 12300113 | Authenticator service not found. | 1417| 12300114 | Authenticator service exception. | 1418 1419**Example** 1420 1421 ```js 1422 1423 1424 function onResultCallback(code, authResult) { 1425 console.log("resultCode: " + code); 1426 console.log("authResult: " + JSON.stringify(authResult)); 1427 } 1428 1429 function onRequestRedirectedCallback(request) { 1430 let wantInfo = { 1431 deviceId: '', 1432 bundleName: 'com.example.accountjsdemo', 1433 action: 'ohos.want.action.viewData', 1434 entities: ['entity.system.default'], 1435 } 1436 this.context.startAbility(wantInfo).then(() => { 1437 console.log("startAbility successfully"); 1438 }).catch((err) => { 1439 console.log("startAbility err: " + JSON.stringify(err)); 1440 }) 1441 } 1442 1443 let options = { 1444 "password": "xxxx", 1445 }; 1446 try { 1447 appAccountManager.auth("LiSi", "com.example.accountjsdemo", "getSocialData", options, { 1448 onResult: onResultCallback, 1449 onRequestRedirected: onRequestRedirectedCallback 1450 }); 1451 } catch (err) { 1452 console.log("auth exception: " + JSON.stringify(err)); 1453 } 1454 ``` 1455 1456### getAuthToken<sup>9+</sup> 1457 1458getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 1459 1460Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 1461 1462**System capability**: SystemCapability.Account.AppAccount 1463 1464**Parameters** 1465 1466| Name | Type | Mandatory | Description | 1467| -------- | --------------------------- | ---- | ----------- | 1468| name | string | Yes | Name of the target app account. | 1469| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 1470| authType | string | Yes | Authentication type. | 1471| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | 1472 1473**Error codes** 1474 1475| ID| Error Message| 1476| ------- | -------| 1477| 12300001 | System service exception. | 1478| 12300002 | Invalid name, owner or authType. | 1479| 12300003 | Account not found. | 1480| 12300107 | AuthType not found. | 1481 1482**Example** 1483 1484 ```js 1485 try { 1486 appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, token) => { 1487 if (err) { 1488 console.log("getAuthToken failed, error: " + JSON.stringify(err)); 1489 } else { 1490 console.log("getAuthToken successfully, token: " + token); 1491 } 1492 }); 1493 } catch (err) { 1494 console.log("getAuthToken exception: " + JSON.stringify(err)); 1495 } 1496 ``` 1497 1498### getAuthToken<sup>9+</sup> 1499 1500getAuthToken(name: string, owner: string, authType: string): Promise<string> 1501 1502Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 1503 1504**System capability**: SystemCapability.Account.AppAccount 1505 1506**Parameters** 1507 1508| Name | Type | Mandatory | Description | 1509| -------- | ------ | ---- | ----------- | 1510| name | string | Yes | Name of the target app account. | 1511| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 1512| authType | string | Yes | Authentication type. | 1513 1514**Return value** 1515 1516| Type | Description | 1517| --------------------- | --------------------- | 1518| Promise<string> | Promise used to return the authorization token obtained.| 1519 1520**Error codes** 1521 1522| ID| Error Message| 1523| ------- | ------- | 1524| 12300001 | System service exception. | 1525| 12300002 | Invalid name or owner or authType. | 1526| 12300003 | Account not found. | 1527| 12300107 | AuthType not found. | 1528 1529**Example** 1530 1531 ```js 1532 try { 1533 appAccountManager.getAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((token) => { 1534 console.log("getAuthToken successfully, token: " + token); 1535 }).catch((err) => { 1536 console.log("getAuthToken failed, error: " + JSON.stringify(err)); 1537 }); 1538 } catch (err) { 1539 console.log("getAuthToken exception: " + JSON.stringify(err)); 1540 } 1541 ``` 1542 1543### setAuthToken<sup>9+</sup> 1544 1545setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 1546 1547Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. 1548 1549**System capability**: SystemCapability.Account.AppAccount 1550 1551**Parameters** 1552 1553| Name | Type | Mandatory | Description | 1554| -------- | ------------------------- | ---- | -------- | 1555| name | string | Yes | Name of the target app account.| 1556| authType | string | Yes | Authentication type. | 1557| token | string | Yes | Token to set.| 1558| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1559 1560**Error codes** 1561 1562| ID| Error Message| 1563| ------- | -------| 1564| 12300001 | System service exception. | 1565| 12300002 | Invalid name or authType or token. | 1566| 12300003 | Account not found. | 1567| 12400004 | The number of token reaches the upper limit. | 1568 1569**Example** 1570 1571 ```js 1572 try { 1573 appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx", (err) => { 1574 if (err) { 1575 console.log("setAuthToken failed, error: " + JSON.stringify(err)); 1576 } else { 1577 console.log("setAuthToken successfully"); 1578 } 1579 }); 1580 } catch (err) { 1581 console.log('setAuthToken exception: ' + JSON.stringify(err)); 1582 } 1583 ``` 1584 1585### setAuthToken<sup>9+</sup> 1586 1587setAuthToken(name: string, authType: string, token: string): Promise<void> 1588 1589Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. 1590 1591**System capability**: SystemCapability.Account.AppAccount 1592 1593**Parameters** 1594 1595| Name | Type | Mandatory | Description | 1596| -------- | ------ | ---- | -------- | 1597| name | string | Yes | Name of the target app account.| 1598| authType | string | Yes | Authentication type. | 1599| token | string | Yes | Token to set.| 1600 1601**Return value** 1602 1603| Type | Description | 1604| ------------------- | --------------------- | 1605| Promise<void> | Promise that returns no value.| 1606 1607**Error codes** 1608 1609| ID| Error Message| 1610| ------- | -------| 1611| 12300001 | System service exception. | 1612| 12300002 | Invalid name or authType or token. | 1613| 12300003 | Account not found. | 1614| 12400004 | The number of token reaches the upper limit. | 1615 1616**Example** 1617 1618 ```js 1619 try { 1620 appAccountManager.setAuthToken("LiSi", "getSocialData", "xxxx").then(() => { 1621 console.log("setAuthToken successfully"); 1622 }).catch((err) => { 1623 console.log("setAuthToken failed, error: " + JSON.stringify(err)); 1624 }); 1625 } catch (err) { 1626 console.log("setAuthToken exception: " + JSON.stringify(err)); 1627 } 1628 ``` 1629 1630### deleteAuthToken<sup>9+</sup> 1631 1632deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 1633 1634Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 1635 1636**System capability**: SystemCapability.Account.AppAccount 1637 1638**Parameters** 1639 1640| Name | Type | Mandatory | Description | 1641| -------- | ------------------------- | ---- | ------------ | 1642| name | string | Yes | Name of the target app account. | 1643| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1644| authType | string | Yes | Authentication type. | 1645| token | string | Yes | Authorization token to delete.| 1646| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 1647 1648**Error codes** 1649 1650| ID| Error Message| 1651| ------- | ------- | 1652| 12300001 | System service exception. | 1653| 12300002 | Invalid name or owner or authType or token. | 1654| 12300003 | Account not found. | 1655| 12300107 | AuthType not found. | 1656 1657**Example** 1658 1659 ```js 1660 try { 1661 appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => { 1662 if (err) { 1663 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1664 } else { 1665 console.log("deleteAuthToken successfully"); 1666 } 1667 }); 1668 } catch (err) { 1669 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1670 } 1671 ``` 1672 1673### deleteAuthToken<sup>9+</sup> 1674 1675deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 1676 1677Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 1678 1679**System capability**: SystemCapability.Account.AppAccount 1680 1681**Parameters** 1682 1683| Name | Type | Mandatory | Description | 1684| -------- | ------ | ---- | ------------ | 1685| name | string | Yes | Name of the target app account. | 1686| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 1687| authType | string | Yes | Authentication type. | 1688| token | string | Yes | Authorization token to delete.| 1689 1690**Return value** 1691 1692| Type | Description | 1693| ------------------- | --------------------- | 1694| Promise<void> | Promise that returns no value.| 1695 1696**Error codes** 1697 1698| ID| Error Message| 1699| ------- | ------- | 1700| 12300001 | System service exception. | 1701| 12300002 | Invalid name or owner or authType or token. | 1702| 12300003 | Account not found. | 1703| 12300107 | AuthType not found. | 1704 1705**Example** 1706 1707 ```js 1708 try { 1709 appAccountManager.deleteAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => { 1710 console.log("deleteAuthToken successfully"); 1711 }).catch((err) => { 1712 console.log('deleteAuthToken failed, error: ' + JSON.stringify(err)); 1713 }); 1714 } catch (err) { 1715 console.log('deleteAuthToken exception: ' + JSON.stringify(err)); 1716 } 1717 ``` 1718 1719### setAuthTokenVisibility<sup>9+</sup> 1720 1721setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 1722 1723Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. 1724 1725**System capability**: SystemCapability.Account.AppAccount 1726 1727**Parameters** 1728 1729| Name | Type | Mandatory | Description | 1730| ---------- | ------------------------- | ---- | ------------------------- | 1731| name | string | Yes | Name of the target app account. | 1732| authType | string | Yes | Authentication type. | 1733| bundleName | string | Yes | Bundle name of the app. | 1734| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| 1735| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 1736 1737**Error codes** 1738 1739| ID| Error Message| 1740| ------- | -------| 1741| 12300001 | System service exception. | 1742| 12300002 | Invalid name or authType or bundleName. | 1743| 12300003 | Account not found. | 1744| 12300107 | AuthType not found. | 1745| 12400001 | Application not found. | 1746| 12400005 | The size of authorization list reaches the upper limit. | 1747 1748**Example** 1749 1750 ```js 1751 try { 1752 appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => { 1753 if (err) { 1754 console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err)); 1755 } else { 1756 console.log("setAuthTokenVisibility successfully"); 1757 } 1758 }); 1759 } catch (err) { 1760 console.log("setAuthTokenVisibility exception: " + JSON.stringify(err)); 1761 } 1762 ``` 1763 1764### setAuthTokenVisibility<sup>9+</sup> 1765 1766setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 1767 1768Sets the visibility of an authorization token to an app. This API uses a promise to return the result. 1769 1770**System capability**: SystemCapability.Account.AppAccount 1771 1772**Parameters** 1773 1774| Name | Type | Mandatory | Description | 1775| ---------- | ------------------------- | ---- | ------------------------- | 1776| name | string | Yes | Name of the target app account. | 1777| authType | string | Yes | Authentication type. | 1778| bundleName | string | Yes | Bundle name of the app. | 1779| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| 1780 1781**Return value** 1782 1783| Type | Description | 1784| ------------------- | --------------------- | 1785| Promise<void> | Promise that returns no value.| 1786 1787**Error codes** 1788 1789| ID| Error Message| 1790| ------- | -------| 1791| 12300001 | System service exception. | 1792| 12300002 | Invalid name or authType or bundleName. | 1793| 12300003 | Account not found. | 1794| 12300107 | AuthType not found. | 1795| 12400001 | Application not found. | 1796| 12400005 | The size of authorization list reaches the upper limit. | 1797 1798**Example** 1799 1800 ```js 1801 try { 1802 appAccountManager.setAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => { 1803 console.log("setAuthTokenVisibility successfully"); 1804 }).catch((err) => { 1805 console.log("setAuthTokenVisibility failed, error: " + JSON.stringify(err)); 1806 }); 1807 } catch (err) { 1808 console.log("setAuthTokenVisibility exception: " + JSON.stringify(err)); 1809 } 1810 ``` 1811 1812### checkAuthTokenVisibility<sup>9+</sup> 1813 1814checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 1815 1816Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. 1817 1818**System capability**: SystemCapability.Account.AppAccount 1819 1820**Parameters** 1821 1822| Name | Type | Mandatory | Description | 1823| ---------- | ---------------------------- | ---- | ----------- | 1824| name | string | Yes | Name of the target app account. | 1825| authType | string | Yes | Authentication type. | 1826| bundleName | string | Yes | Bundle name of the app.| 1827| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | 1828 1829**Error codes** 1830 1831| ID| Error Message| 1832| ------- | -------| 1833| 12300001 | System service exception. | 1834| 12300002 | Invalid name or authType or bundleName. | 1835| 12300003 | Account not found. | 1836| 12300107 | AuthType not found. | 1837| 12400001 | Application not found. | 1838 1839**Example** 1840 1841 ```js 1842 try { 1843 appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, isVisible) => { 1844 if (err) { 1845 console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err)); 1846 } else { 1847 console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible); 1848 } 1849 }); 1850 } catch (err) { 1851 console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err)); 1852 } 1853 ``` 1854 1855### checkAuthTokenVisibility<sup>9+</sup> 1856 1857checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 1858 1859Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. 1860 1861**System capability**: SystemCapability.Account.AppAccount 1862 1863**Parameters** 1864 1865| Name | Type | Mandatory | Description | 1866| ---------- | ------ | ---- | ------------- | 1867| name | string | Yes | Name of the target app account. | 1868| authType | string | Yes | Authentication type. | 1869| bundleName | string | Yes | Bundle name of the app.| 1870 1871**Return value** 1872 1873| Type | Description | 1874| ---------------------- | --------------------- | 1875| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| 1876 1877**Error codes** 1878 1879| ID| Error Message| 1880| ------- | -------| 1881| 12300001 | System service exception. | 1882| 12300002 | Invalid name or authType or bundleName. | 1883| 12300003 | Account not found. | 1884| 12300107 | AuthType not found. | 1885| 12400001 | Application not found. | 1886 1887**Example** 1888 1889 ```js 1890 try { 1891 appAccountManager.checkAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((isVisible) => { 1892 console.log("checkAuthTokenVisibility successfully, isVisible: " + isVisible); 1893 }).catch((err) => { 1894 console.log("checkAuthTokenVisibility failed, error: " + JSON.stringify(err)); 1895 }); 1896 } catch (err) { 1897 console.log("checkAuthTokenVisibility exception: " + JSON.stringify(err)); 1898 } 1899 ``` 1900 1901### getAllAuthTokens<sup>9+</sup> 1902 1903getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void 1904 1905Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. 1906 1907**System capability**: SystemCapability.Account.AppAccount 1908 1909**Parameters** 1910 1911| Name | Type | Mandatory | Description | 1912| -------- | ---------------------------------------- | ---- | ----------- | 1913| name | string | Yes | Name of the target app account. | 1914| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 1915| callback | AsyncCallback<Array<[AuthTokenInfo](#authtokeninfo9)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | 1916 1917**Error codes** 1918 1919| ID| Error Message| 1920| ------- | -------| 1921| 12300001 | System service exception. | 1922| 12300002 | Invalid name or owner. | 1923| 12300003 | Account not found. | 1924 1925**Example** 1926 1927 ```js 1928 try { 1929 appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo", (err, tokenArr) => { 1930 if (err) { 1931 console.log("getAllAuthTokens failed, error: " + JSON.stringify(err)); 1932 } else { 1933 console.log('getAllAuthTokens successfully, tokenArr: ' + tokenArr); 1934 } 1935 }); 1936 } catch (err) { 1937 console.log("getAllAuthTokens exception: " + JSON.stringify(err)); 1938 } 1939 ``` 1940 1941### getAllAuthTokens<sup>9+</sup> 1942 1943getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>> 1944 1945Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. 1946 1947**System capability**: SystemCapability.Account.AppAccount 1948 1949**Parameters** 1950 1951| Name | Type | Mandatory | Description | 1952| ----- | ------ | ---- | ----------- | 1953| name | string | Yes | Name of the target app account. | 1954| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 1955 1956**Return value** 1957 1958| Type | Description | 1959| ---------------------------------------- | --------------------- | 1960| Promise<Array<[AuthTokenInfo](#authtokeninfo9)>> | Promise used to return the tokens obtained.| 1961 1962**Error codes** 1963 1964| ID| Error Message| 1965| ------- | -------| 1966| 12300001 | System service exception. | 1967| 12300002 | Invalid name or owner. | 1968| 12300003 | Account not found. | 1969 1970**Example** 1971 1972 ```js 1973 try { 1974 appAccountManager.getAllAuthTokens("LiSi", "com.example.accountjsdemo").then((tokenArr) => { 1975 console.log('getAllAuthTokens successfully, tokenArr: ' + JSON.stringify(tokenArr)); 1976 }).catch((err) => { 1977 console.log("getAllAuthTokens failed, error: " + JSON.stringify(err)); 1978 }); 1979 } catch (err) { 1980 console.log("getAllAuthTokens exception: " + JSON.stringify(err)); 1981 } 1982 ``` 1983 1984### getAuthList<sup>9+</sup> 1985 1986getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 1987 1988Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses an asynchronous callback to return the result. 1989 1990**System capability**: SystemCapability.Account.AppAccount 1991 1992**Parameters** 1993 1994| Name | Type | Mandatory | Description | 1995| -------- | ---------------------------------------- | ---- | ----------------------- | 1996| name | string | Yes | Name of the target app account. | 1997| authType | string | Yes | Authentication type.| 1998| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object.| 1999 2000**Error codes** 2001 2002| ID| Error Message| 2003| ------- | -------| 2004| 12300001 | System service exception. | 2005| 12300002 | Invalid name or authType. | 2006| 12300003 | Account not found. | 2007| 12300107 | AuthType not found. | 2008 2009**Example** 2010 2011 ```js 2012 try { 2013 appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData", (err, authList) => { 2014 if (err) { 2015 console.log("getAuthList failed, error: " + JSON.stringify(err)); 2016 } else { 2017 console.log("getAuthList successfully, authList: " + authList); 2018 } 2019 }); 2020 } catch (err) { 2021 console.log('getAuthList exception: ' + JSON.stringify(err)); 2022 } 2023 ``` 2024 2025### getAuthList<sup>9+</sup> 2026 2027getAuthList(name: string, authType: string): Promise<Array<string>> 2028 2029Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by [setAuthTokenVisibility](#setauthtokenvisibility9). This API uses a promise to return the result. 2030 2031**System capability**: SystemCapability.Account.AppAccount 2032 2033**Parameters** 2034 2035| Name | Type | Mandatory | Description | 2036| -------- | ------ | ---- | ------------------------------ | 2037| name | string | Yes | Name of the target app account. | 2038| authType | string | Yes | Authentication type.| 2039 2040**Return value** 2041 2042| Type | Description | 2043| ---------------------------------- | --------------------- | 2044| Promise<Array<string>> | Promise used to return a list of authorized bundles.| 2045 2046**Error codes** 2047 2048| ID| Error Message| 2049| ------- | -------| 2050| 12300001 | System service exception. | 2051| 12300002 | Invalid name or authType. | 2052| 12300003 | Account not found. | 2053| 12300107 | AuthType not found. | 2054 2055**Example** 2056 2057 ```js 2058 try { 2059 appAccountManager.getAuthList("com.example.accountjsdemo", "getSocialData").then((authList) => { 2060 console.log("getAuthList successfully, authList: " + authList); 2061 }).catch((err) => { 2062 console.log("getAuthList failed, error: " + JSON.stringify(err)); 2063 }); 2064 } catch (err) { 2065 console.log("getAuthList exception: " + JSON.stringify(err)); 2066 } 2067 ``` 2068 2069### getAuthCallback<sup>9+</sup> 2070 2071getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void 2072 2073Obtains the authenticator callback for the authentication session. This API uses an asynchronous callback to return the result. 2074 2075**System capability**: SystemCapability.Account.AppAccount 2076 2077**Parameters** 2078 2079| Name | Type | Mandatory | Description | 2080| --------- | ---------------------------------------- | ---- | -------- | 2081| sessionId | string | Yes | ID of the authentication session.| 2082| callback | AsyncCallback<[AuthCallback](#authcallback9)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback object obtained. Otherwise, **err** is an error object.| 2083 2084**Error codes** 2085 2086| ID| Error Message| 2087| ------- | ------- | 2088| 12300001 | System service exception. | 2089| 12300002 | Invalid sessionId. | 2090| 12300108 | Session not found. | 2091 2092**Example** 2093 2094 ```js 2095 import featureAbility from '@ohos.ability.featureAbility'; 2096 featureAbility.getWant((err, want) => { 2097 var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; 2098 try { 2099 appAccountManager.getAuthCallback(sessionId, (err, callback) => { 2100 if (err.code != account_appAccount.ResultCode.SUCCESS) { 2101 console.log("getAuthCallback err: " + JSON.stringify(err)); 2102 return; 2103 } 2104 var result = { 2105 accountInfo: { 2106 name: "Lisi", 2107 owner: "com.example.accountjsdemo", 2108 }, 2109 tokenInfo: { 2110 token: "xxxxxx", 2111 authType: "getSocialData" 2112 } 2113 }; 2114 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 2115 }); 2116 } catch (err) { 2117 console.log("getAuthCallback exception: " + JSON.stringify(err)); 2118 } 2119 }); 2120 ``` 2121 2122### getAuthCallback<sup>9+</sup> 2123 2124getAuthCallback(sessionId: string): Promise<AuthCallback> 2125 2126Obtains the authenticator callback for the authentication session. This API uses a promise to return the result. 2127 2128**System capability**: SystemCapability.Account.AppAccount 2129 2130**Parameters** 2131 2132| Name | Type | Mandatory | Description | 2133| --------- | ------ | ---- | -------- | 2134| sessionId | string | Yes | ID of the authentication session.| 2135 2136**Return value** 2137 2138| Type | Description | 2139| ------------------------------------ | --------------------- | 2140| Promise<[AuthCallback](#authcallback9)> | Promise used to return the authenticator callback obtained.| 2141 2142**Error codes** 2143 2144| ID| Error Message| 2145| ------- | ------- | 2146| 12300001 | System service exception. | 2147| 12300002 | Invalid sessionId. | 2148| 12300108 | Session not found. | 2149 2150**Example** 2151 2152 ```js 2153 import featureAbility from '@ohos.ability.featureAbility'; 2154 2155 featureAbility.getWant().then((want) => { 2156 var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; 2157 try { 2158 appAccountManager.getAuthCallback(sessionId).then((callback) => { 2159 var result = { 2160 accountInfo: { 2161 name: "Lisi", 2162 owner: "com.example.accountjsdemo", 2163 }, 2164 tokenInfo: { 2165 token: "xxxxxx", 2166 authType: "getSocialData" 2167 } 2168 }; 2169 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 2170 }).catch((err) => { 2171 console.log("getAuthCallback err: " + JSON.stringify(err)); 2172 }); 2173 } catch (err) { 2174 console.log("getAuthCallback exception: " + JSON.stringify(err)); 2175 } 2176 }).catch((err) => { 2177 console.log("getWant err: " + JSON.stringify(err)); 2178 }); 2179 ``` 2180 2181### queryAuthenticatorInfo<sup>9+</sup> 2182 2183queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 2184 2185Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. 2186 2187**System capability**: SystemCapability.Account.AppAccount 2188 2189**Parameters** 2190 2191| Name | Type | Mandatory | Description | 2192| -------- | -------------------------------------- | ---- | ----------- | 2193| owner | string | Yes | Bundle name of the app.| 2194| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | 2195 2196**Error codes** 2197 2198| ID| Error Message| 2199| ------- | -------| 2200| 12300001 | System service exception. | 2201| 12300002 | Invalid owner. | 2202| 12300113 | Authenticator service not found. | 2203 2204**Example** 2205 2206 ```js 2207 try { 2208 appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo", (err, info) => { 2209 if (err) { 2210 console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err)); 2211 } else { 2212 console.log('queryAuthenticatorInfo successfully, info: ' + JSON.stringify(info)); 2213 } 2214 }); 2215 } catch (err) { 2216 console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err)); 2217 } 2218 ``` 2219 2220### queryAuthenticatorInfo<sup>9+</sup> 2221 2222queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 2223 2224Obtains the authenticator information of an app. This API uses a promise to return the result. 2225 2226**System capability**: SystemCapability.Account.AppAccount 2227 2228**Parameters** 2229 2230| Name | Type | Mandatory | Description | 2231| ----- | ------ | ---- | ----------- | 2232| owner | string | Yes | Bundle name of the app.| 2233 2234**Return value** 2235 2236| Type | Description | 2237| -------------------------------- | --------------------- | 2238| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| 2239 2240**Error codes** 2241 2242| ID| Error Message| 2243| ------- | -------| 2244| 12300001 | System service exception. | 2245| 12300002 | Invalid owner. | 2246| 12300113 | Authenticator service not found. | 2247 2248**Example** 2249 2250 ```js 2251 try { 2252 appAccountManager.queryAuthenticatorInfo("com.example.accountjsdemo").then((info) => { 2253 console.log("queryAuthenticatorInfo successfully, info: " + JSON.stringify(info)); 2254 }).catch((err) => { 2255 console.log("queryAuthenticatorInfo failed, error: " + JSON.stringify(err)); 2256 }); 2257 } catch (err) { 2258 console.log("queryAuthenticatorInfo exception: " + JSON.stringify(err)); 2259 } 2260 ``` 2261 2262### checkAccountLabels<sup>9+</sup> 2263 2264checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void; 2265 2266Checks whether an app account has specific labels. This API uses an asynchronous callback to return the result. The labels are checked by the authenticator of the target app. 2267 2268**System capability**: SystemCapability.Account.AppAccount 2269 2270**Parameters** 2271 2272| Name | Type | Mandatory | Description | 2273| -------------- | ------------------------- | ----- | --------------- | 2274| name | string | Yes | Name of the target app account. | 2275| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 2276| labels | Array<string> | Yes | Labels to check. | 2277| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** or **false**. The value **true** means the app account has the labels; the value **false** means the opposite. If the operation fails, **err** is an error object. | 2278 2279**Error codes** 2280 2281| ID| Error Message| 2282| ------- | ------- | 2283| 12300001 | System service exception. | 2284| 12300002 | Invalid name or owner or labels. | 2285| 12300003 | Account not found. | 2286| 12300010 | Account service busy. | 2287| 12300113 | Authenticator service not found. | 2288| 12300114 | Authenticator service exception. | 2289 2290**Example** 2291 2292 ```js 2293 let labels = ["student"]; 2294 try { 2295 appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels, (err, hasAllLabels) => { 2296 if (err) { 2297 console.log("checkAccountLabels failed, error: " + JSON.stringify(err)); 2298 } else { 2299 console.log("checkAccountLabels successfully, hasAllLabels: " + hasAllLabels); 2300 } 2301 }); 2302 } catch (err) { 2303 console.log("checkAccountLabels exception: " + JSON.stringify(err)); 2304 } 2305 ``` 2306 2307### checkAccountLabels<sup>9+</sup> 2308 2309checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean> 2310 2311Checks whether an app account has specific labels. This API uses a promise to return the result. The labels are checked by the authenticator of the target app. 2312 2313**System capability**: SystemCapability.Account.AppAccount 2314 2315**Parameters** 2316 2317| Name | Type | Mandatory | Description | 2318| -------------- | ------------------------- | ----- | --------------- | 2319| name | string | Yes | Name of the target app account. | 2320| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 2321| labels | Array<string> | Yes | Labels to check. | 2322 2323**Return value** 2324 2325| Type | Description | 2326| ------------------- | -------------------------------- | 2327| Promise<boolean> | Promise used to return the result. The value **true** means the app account has the labels; the value **false** means the opposite.| 2328 2329**Error codes** 2330 2331| ID| Error Message| 2332| ------- | ------- | 2333| 12300001 | System service exception. | 2334| 12300002 | Invalid name or owner or labels. | 2335| 12300003 | Account not found. | 2336| 12300010 | Account service busy. | 2337| 12300113 | Authenticator service not found. | 2338| 12300114 | Authenticator service exception. | 2339 2340**Example** 2341 2342 ```js 2343 let labels = ["student"]; 2344 try { 2345 appAccountManager.checkAccountLabels("zhangsan", "com.example.accountjsdemo", labels).then((hasAllLabels) => { 2346 console.log('checkAccountLabels successfully: ' + hasAllLabels); 2347 }).catch((err) => { 2348 console.log("checkAccountLabels failed, error: " + JSON.stringify(err)); 2349 }); 2350 } catch (err) { 2351 console.log("checkAccountLabels exception: " + JSON.stringify(err)); 2352 } 2353 ``` 2354 2355### deleteCredential<sup>9+</sup> 2356 2357deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void 2358 2359Deletes the credential of the specified type from an app account. This API uses an asynchronous callback to return the result. 2360 2361**System capability**: SystemCapability.Account.AppAccount 2362 2363**Parameters** 2364 2365| Name | Type | Mandatory | Description | 2366| -------------- | ------------------------- | ----- | -------------- | 2367| name | string | Yes | Name of the target app account.| 2368| credentialType | string | Yes | Type of the credential to delete. | 2369| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2370 2371**Error codes** 2372 2373| ID| Error Message| 2374| ------- | ------- | 2375| 12300001 | System service exception. | 2376| 12300002 | Invalid name or credentialType. | 2377| 12300003 | Account not found. | 2378| 12300102 | Credential not found. | 2379 2380**Example** 2381 2382 ```js 2383 try { 2384 appAccountManager.deleteCredential("zhangsan", "PIN_SIX", (err) => { 2385 if (err) { 2386 console.log("deleteCredential failed, error: " + JSON.stringify(err)); 2387 } else { 2388 console.log("deleteCredential successfully"); 2389 } 2390 }); 2391 } catch (err) { 2392 console.log("deleteCredential exception: " + JSON.stringify(err)); 2393 } 2394 ``` 2395 2396### deleteCredential<sup>9+</sup> 2397 2398deleteCredential(name: string, credentialType: string): Promise<void> 2399 2400Deletes the credential of the specified type from an app account. This API uses a promise to return the result. 2401 2402**System capability**: SystemCapability.Account.AppAccount 2403 2404**Parameters** 2405 2406| Name | Type | Mandatory | Description | 2407| -------------- | ------ | ----- | --------------- | 2408| name | string | Yes | Name of the target app account.| 2409| credentialType | string | Yes | Type of the credential to delete. | 2410 2411**Return value** 2412 2413| Type | Description | 2414| ------------------- | -------------------------------- | 2415| Promise<void> | Promise that returns no value.| 2416 2417**Error codes** 2418 2419| ID| Error Message| 2420| ------- | ------- | 2421| 12300001 | System service exception. | 2422| 12300002 | Invalid name or credentialType. | 2423| 12300003 | Account not found. | 2424| 12300102 | Credential not found. | 2425 2426**Example** 2427 2428 ```js 2429 try { 2430 appAccountManager.deleteCredential("zhangsan", "PIN_SIX").then(() => { 2431 console.log("deleteCredential successfully"); 2432 }).catch((err) => { 2433 console.log("deleteCredential failed, error: " + JSON.stringify(err)); 2434 }); 2435 } catch (err) { 2436 console.log("deleteCredential exception: " + JSON.stringify(err)); 2437 } 2438 ``` 2439 2440### selectAccountsByOptions<sup>9+</sup> 2441 2442selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void 2443 2444Selects the accounts that can be accessed by the invoker based on the options. This API uses an asynchronous callback to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels. 2445 2446**System capability**: SystemCapability.Account.AppAccount 2447 2448**Parameters** 2449 2450| Name | Type | Mandatory | Description | 2451| -------------- | ----------------------------------- | ----- | --------------- | 2452| options | SelectAccountsOptions | Yes | Options for selecting accounts. | 2453| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accounts selected. Otherwise, **err** is an error object. | 2454 2455**Error codes** 2456 2457| ID| Error Message| 2458| ------- | ------- | 2459| 12300001 | System service exception. | 2460| 12300002 | Invalid options. | 2461| 12300010 | Account service busy. | 2462| 12300114 | Authenticator service exception. | 2463 2464**Example** 2465 2466 ```js 2467 let options = { 2468 allowedOwners: [ "com.example.accountjsdemo" ], 2469 requiredLabels: [ "student" ] 2470 }; 2471 try { 2472 appAccountManager.selectAccountsByOptions(options, (err, accountArr) => { 2473 if (err) { 2474 console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err)); 2475 } else { 2476 console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr)); 2477 } 2478 }); 2479 } catch (err) { 2480 console.log("selectAccountsByOptions exception: " + JSON.stringify(err)); 2481 } 2482 ``` 2483 2484### selectAccountsByOptions<sup>9+</sup> 2485 2486selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>> 2487 2488Selects the accounts that can be accessed by the invoker based on the options. This API uses a promise to return the result. If the options contain label constraints, the authenticator of the target app provides the capability of checking the labels. 2489 2490**System capability**: SystemCapability.Account.AppAccount 2491 2492**Parameters** 2493 2494| Name | Type | Mandatory | Description | 2495| -------------- | ------------------------- | ----- | --------------- | 2496| options | [SelectAccountsOptions](#selectaccountsoptions9) | Yes | Options for selecting accounts. | 2497 2498**Return value** 2499 2500| Type | Description | 2501| ------------------- | -------------------------------- | 2502| Promise<[AppAccountInfo](#appaccountinfo)> | Promise used to return the accounts selected.| 2503 2504**Error codes** 2505 2506| ID| Error Message| 2507| ------- | ------- | 2508| 12300001 | System service exception. | 2509| 12300002 | Invalid options. | 2510| 12300010 | Account service busy. | 2511| 12300114 | Authenticator service exception. | 2512 2513**Example** 2514 2515 ```js 2516 let options = { 2517 allowedOwners: ["com.example.accountjsdemo"] 2518 }; 2519 try { 2520 appAccountManager.selectAccountsByOptions(options).then((accountArr) => { 2521 console.log("selectAccountsByOptions successfully, accountArr: " + JSON.stringify(accountArr)); 2522 }).catch((err) => { 2523 console.log("selectAccountsByOptions failed, error: " + JSON.stringify(err)); 2524 }); 2525 } catch (err) { 2526 console.log("selectAccountsByOptions exception: " + JSON.stringify(err)); 2527 } 2528 ``` 2529 2530### verifyCredential<sup>9+</sup> 2531 2532verifyCredential(name: string, owner: string, callback: AuthCallback): void; 2533 2534Verifies the credential of an app account. This API uses an asynchronous callback to return the result. 2535 2536**System capability**: SystemCapability.Account.AppAccount 2537 2538**Parameters** 2539 2540| Name | Type | Mandatory | Description | 2541| -------- | --------------------- | ----- | ----------------------- | 2542| name | string | Yes | Name of the target app account. | 2543| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2544| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| 2545 2546**Error codes** 2547 2548| ID| Error Message| 2549| ------- | -------| 2550| 12300001 | System service exception. | 2551| 12300002 | Invalid name or owner. | 2552| 12300003 | Account not found. | 2553| 12300010 | Account service busy. | 2554| 12300113 | Authenticator service not found. | 2555| 12300114 | Authenticator service exception. | 2556 2557**Example** 2558 2559 ```js 2560 try { 2561 appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", { 2562 onResult: (resultCode, result) => { 2563 console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); 2564 console.log("verifyCredential onResult, result:" + JSON.stringify(result)); 2565 }, 2566 onRequestRedirected: (request) => { 2567 console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); 2568 } 2569 }); 2570 } catch (err) { 2571 console.log("verifyCredential err: " + JSON.stringify(err)); 2572 } 2573 ``` 2574 2575### verifyCredential<sup>9+</sup> 2576 2577verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void; 2578 2579Verifies the user credential. This API uses an asynchronous callback to return the result. 2580 2581**System capability**: SystemCapability.Account.AppAccount 2582 2583**Parameters** 2584 2585| Name | Type | Mandatory | Description | 2586| -------- | ----------------------- | ----- | ----------------------- | 2587| name | string | Yes | Name of the target app account. | 2588| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2589| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for verifying the user credential. | 2590| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| 2591 2592**Error codes** 2593 2594| ID| Error Message| 2595| ------- | -------| 2596| 12300001 | System service exception. | 2597| 12300002 | Invalid name or owner or options. | 2598| 12300003 | Account not found. | 2599| 12300010 | Account service busy. | 2600| 12300113 | Authenticator service not found. | 2601| 12300114 | Authenticator service exception. | 2602 2603**Example** 2604 2605 ```js 2606 let options = { 2607 credentialType: "pin", 2608 credential: "123456" 2609 }; 2610 try { 2611 appAccountManager.verifyCredential("zhangsan", "com.example.accountjsdemo", options, { 2612 onResult: (resultCode, result) => { 2613 console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); 2614 console.log("verifyCredential onResult, result:" + JSON.stringify(result)); 2615 }, 2616 onRequestRedirected: (request) => { 2617 console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); 2618 } 2619 }); 2620 } catch (err) { 2621 console.log("verifyCredential err: " + JSON.stringify(err)); 2622 } 2623 ``` 2624 2625### setAuthenticatorProperties<sup>9+</sup> 2626 2627setAuthenticatorProperties(owner: string, callback: AuthCallback): void; 2628 2629Sets the authenticator attributes of an app. This API uses an asynchronous callback to return the result. 2630 2631**System capability**: SystemCapability.Account.AppAccount 2632 2633**Parameters** 2634 2635| Name | Type | Mandatory | Description | 2636| -------- | --------------------- | ----- | ----------------------- | 2637| owner | string | Yes | Owner of the authenticator. | 2638| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| 2639 2640**Error codes** 2641 2642| ID| Error Message| 2643| ------- | ------- | 2644| 12300001 | System service exception. | 2645| 12300002 | Invalid owner. | 2646| 12300010 | Account service busy. | 2647| 12300113 | Authenticator service not found. | 2648| 12300114 | Authenticator service exception. | 2649 2650**Example** 2651 2652 ```js 2653 try { 2654 appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", { 2655 onResult: (resultCode, result) => { 2656 console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); 2657 console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); 2658 }, 2659 onRequestRedirected: (request) => { 2660 console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); 2661 } 2662 }); 2663 } catch (err) { 2664 console.log("setAuthenticatorProperties err: " + JSON.stringify(err)); 2665 } 2666 ``` 2667 2668### setAuthenticatorProperties<sup>9+</sup> 2669 2670setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void; 2671 2672Set authenticator properties. This API uses an asynchronous callback to return the result. 2673 2674**System capability**: SystemCapability.Account.AppAccount 2675 2676**Parameters** 2677 2678| Name | Type | Mandatory | Description | 2679| -------- | --------------------- | ----- | ----------------------- | 2680| owner | string | Yes | Owner of the authenticator. | 2681| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 2682| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| 2683 2684**Error codes** 2685 2686| ID| Error Message| 2687| ------- | ------- | 2688| 12300001 | System service exception. | 2689| 12300002 | Invalid owner or options. | 2690| 12300010 | Account service busy. | 2691| 12300113 | Authenticator service not found. | 2692| 12300114 | Authenticator service exception. | 2693 2694**Example** 2695 2696 ```js 2697 let options = { 2698 properties: {"prop1": "value1"} 2699 }; 2700 try { 2701 appAccountManager.setAuthenticatorProperties("com.example.accountjsdemo", options, { 2702 onResult: (resultCode, result) => { 2703 console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); 2704 console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); 2705 }, 2706 onRequestRedirected: (request) => { 2707 console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); 2708 } 2709 }); 2710 } catch (err) { 2711 console.log("setAuthenticatorProperties err: " + JSON.stringify(err)); 2712 } 2713 2714 ``` 2715 2716### addAccount<sup>(deprecated)</sup> 2717 2718addAccount(name: string, callback: AsyncCallback<void>): void 2719 2720Adds an app account. This API uses an asynchronous callback to return the result. 2721 2722> **NOTE** 2723> 2724>This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9). 2725 2726 2727**System capability**: SystemCapability.Account.AppAccount 2728 2729**Parameters** 2730 2731| Name | Type | Mandatory | Description | 2732| -------- | ------------------------- | ---- | -------------------- | 2733| name | string | Yes | Name of the app account to add. | 2734| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2735 2736**Example** 2737 2738 ```js 2739 appAccountManager.addAccount("WangWu", (err) => { 2740 console.log("addAccount err: " + JSON.stringify(err)); 2741 }); 2742 ``` 2743 2744### addAccount<sup>(deprecated)</sup> 2745 2746addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void 2747 2748Adds an app account name and additional information. This API uses an asynchronous callback to return the result. 2749 2750> **NOTE** 2751> 2752> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-1). 2753 2754**System capability**: SystemCapability.Account.AppAccount 2755 2756**Parameters** 2757 2758| Name | Type | Mandatory | Description | 2759| --------- | ------------------------- | ---- | ---------------------------------------- | 2760| name | string | Yes | Name of the target app account. | 2761| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| 2762| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 2763 2764**Example** 2765 2766 ```js 2767 appAccountManager.addAccount("LiSi", "token101", (err) => { 2768 console.log("addAccount err: " + JSON.stringify(err)); 2769 }); 2770 ``` 2771 2772### addAccount<sup>(deprecated)</sup> 2773 2774addAccount(name: string, extraInfo?: string): Promise<void> 2775 2776Adds an app account name and additional information. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. 2777 2778> **NOTE** 2779> 2780> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [createAccount](#createaccount9-2). 2781 2782**System capability**: SystemCapability.Account.AppAccount 2783 2784**Parameters** 2785 2786| Name | Type | Mandatory | Description | 2787| --------- | ------ | ---- | ---------------------------------------- | 2788| name | string | Yes | Name of the target app account. | 2789| extraInfo | string | No | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| 2790 2791**Return value** 2792 2793| Type | Description | 2794| ------------------- | --------------------- | 2795| Promise<void> | Promise that returns no value.| 2796 2797**Example** 2798 2799 ```js 2800 appAccountManager.addAccount("LiSi", "token101").then(()=> { 2801 console.log('addAccount Success'); 2802 }).catch((err) => { 2803 console.log("addAccount err: " + JSON.stringify(err)); 2804 }); 2805 ``` 2806 2807### addAccountImplicitly<sup>(deprecated)</sup> 2808 2809addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void 2810 2811Adds an app account implicitly based on the specified owner. This API uses an asynchronous callback to return the result. 2812 2813> **NOTE** 2814> 2815> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9). 2816 2817**System capability**: SystemCapability.Account.AppAccount 2818 2819**Parameters** 2820 2821| Name | Type | Mandatory | Description | 2822| -------- | --------------------- | ---- | ----------------------- | 2823| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 2824| authType | string | Yes | Authentication type. The authentication type is customized. | 2825| options | {[key: string]: any} | Yes | Authentication options, which can be set as required.| 2826| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the result. | 2827 2828**Example** 2829 2830 ```js 2831 2832 2833 function onResultCallback(code, result) { 2834 console.log("resultCode: " + code); 2835 console.log("result: " + JSON.stringify(result)); 2836 } 2837 2838 function onRequestRedirectedCallback(request) { 2839 let wantInfo = { 2840 deviceId: '', 2841 bundleName: 'com.example.accountjsdemo', 2842 action: 'ohos.want.action.viewData', 2843 entities: ['entity.system.default'], 2844 } 2845 this.context.startAbility(wantInfo).then(() => { 2846 console.log("startAbility successfully"); 2847 }).catch((err) => { 2848 console.log("startAbility err: " + JSON.stringify(err)); 2849 }) 2850 } 2851 2852 appAccountManager.addAccountImplicitly("com.example.accountjsdemo", "getSocialData", {}, { 2853 onResult: onResultCallback, 2854 onRequestRedirected: onRequestRedirectedCallback 2855 }); 2856 ``` 2857 2858### deleteAccount<sup>(deprecated)</sup> 2859 2860deleteAccount(name: string, callback: AsyncCallback<void>): void 2861 2862Deletes an app account. This API uses an asynchronous callback to return the result. 2863 2864> **NOTE** 2865> 2866> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9). 2867 2868**System capability**: SystemCapability.Account.AppAccount 2869 2870**Parameters** 2871 2872| Name | Type | Mandatory | Description | 2873| -------- | ------------------------- | ---- | ---------------- | 2874| name | string | Yes | Name of the app account to delete. | 2875| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2876 2877**Example** 2878 2879 ```js 2880 appAccountManager.deleteAccount("ZhaoLiu", (err) => { 2881 console.log("deleteAccount err: " + JSON.stringify(err)); 2882 }); 2883 ``` 2884 2885### deleteAccount<sup>(deprecated)</sup> 2886 2887deleteAccount(name: string): Promise<void> 2888 2889Deletes an app account. This API uses a promise to return the result. 2890 2891> **NOTE** 2892> 2893> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeAccount](#removeaccount9). 2894 2895**System capability**: SystemCapability.Account.AppAccount 2896 2897**Parameters** 2898 2899| Name | Type | Mandatory | Description | 2900| ---- | ------ | ---- | ----------- | 2901| name | string | Yes | Name of the app account to delete.| 2902 2903**Return value** 2904 2905| Type | Description | 2906| :------------------ | :-------------------- | 2907| Promise<void> | Promise that returns no value.| 2908 2909**Example** 2910 2911 ```js 2912 appAccountManager.deleteAccount("ZhaoLiu").then(() => { 2913 console.log('deleteAccount Success'); 2914 }).catch((err) => { 2915 console.log("deleteAccount err: " + JSON.stringify(err)); 2916 }); 2917 ``` 2918### disableAppAccess<sup>(deprecated)</sup> 2919 2920disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 2921 2922Disables an app account from accessing an app. This API uses an asynchronous callback to return the result. 2923 2924> **NOTE** 2925> 2926> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9). 2927 2928**System capability**: SystemCapability.Account.AppAccount 2929 2930**Parameters** 2931 2932| Name | Type | Mandatory | Description | 2933| ---------- | ------------------------- | ---- | --------------------------------- | 2934| name | string | Yes | Name of the target app account. | 2935| bundleName | string | Yes | Bundle name of the app. | 2936| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 2937 2938**Example** 2939 2940 ```js 2941 appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { 2942 console.log("disableAppAccess err: " + JSON.stringify(err)); 2943 }); 2944 ``` 2945 2946### disableAppAccess<sup>(deprecated)</sup> 2947 2948disableAppAccess(name: string, bundleName: string): Promise<void> 2949 2950Disables an app account from accessing an app. This API uses a promise to return the result. 2951 2952> **NOTE** 2953> 2954> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1). 2955 2956**System capability**: SystemCapability.Account.AppAccount 2957 2958**Parameters** 2959 2960| Name | Type | Mandatory | Description | 2961| ---------- | ------ | ---- | ---------------- | 2962| name | string | Yes | Name of the target app account.| 2963| bundleName | string | Yes | Bundle name of the app. | 2964 2965**Return value** 2966 2967| Type | Description | 2968| :------------------ | :-------------------- | 2969| Promise<void> | Promise that returns no value.| 2970 2971**Example** 2972 2973 ```js 2974 appAccountManager.disableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { 2975 console.log('disableAppAccess Success'); 2976 }).catch((err) => { 2977 console.log("disableAppAccess err: " + JSON.stringify(err)); 2978 }); 2979 ``` 2980 2981### enableAppAccess<sup>(deprecated)</sup> 2982 2983enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void 2984 2985Enables an app account to access an app. This API uses an asynchronous callback to return the result. 2986 2987> **NOTE** 2988> 2989> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9). 2990 2991**System capability**: SystemCapability.Account.AppAccount 2992 2993**Parameters** 2994 2995| Name | Type | Mandatory | Description | 2996| ---------- | ------------------------- | ---- | --------------------------------- | 2997| name | string | Yes | Name of the target app account. | 2998| bundleName | string | Yes | Bundle name of the app. | 2999| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3000 3001**Example** 3002 3003 ```js 3004 appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo", (err) => { 3005 console.log("enableAppAccess: " + JSON.stringify(err)); 3006 }); 3007 ``` 3008 3009### enableAppAccess<sup>(deprecated)</sup> 3010 3011enableAppAccess(name: string, bundleName: string): Promise<void> 3012 3013Enables an app account to access an app. This API uses a promise to return the result. 3014 3015> **NOTE** 3016> 3017> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setAppAccess](#setappaccess9-1). 3018 3019**System capability**: SystemCapability.Account.AppAccount 3020 3021**Parameters** 3022 3023| Name | Type | Mandatory | Description | 3024| ---------- | ------ | ---- | --------- | 3025| name | string | Yes | Name of the target app account. | 3026| bundleName | string | Yes | Bundle name of the app.| 3027 3028**Return value** 3029 3030| Type | Description | 3031| :------------------ | :-------------------- | 3032| Promise<void> | Promise that returns no value.| 3033 3034**Example** 3035 3036 ```js 3037 appAccountManager.enableAppAccess("ZhangSan", "com.example.accountjsdemo").then(() => { 3038 console.log('enableAppAccess Success'); 3039 }).catch((err) => { 3040 console.log("enableAppAccess err: " + JSON.stringify(err)); 3041 }); 3042 ``` 3043 3044### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3045 3046checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void 3047 3048Checks whether data synchronization is enabled for an app account. This API uses an asynchronous callback to return the result. 3049 3050> **NOTE** 3051> 3052> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9). 3053 3054**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3055 3056**System capability**: SystemCapability.Account.AppAccount 3057 3058**Parameters** 3059 3060| Name | Type | Mandatory | Description | 3061| -------- | ---------------------------- | ---- | --------------------- | 3062| name | string | Yes | Name of the target app account. | 3063| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| 3064 3065**Example** 3066 3067 ```js 3068 appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => { 3069 console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); 3070 console.log('checkAppAccountSyncEnable result: ' + result); 3071 }); 3072 ``` 3073 3074### checkAppAccountSyncEnable<sup>(deprecated)</sup> 3075 3076checkAppAccountSyncEnable(name: string): Promise<boolean> 3077 3078Checks whether data synchronization is enabled for an app account. This API uses a promise to return the result. 3079 3080> **NOTE** 3081> 3082> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [checkDataSyncEnabled](#checkdatasyncenabled9-1). 3083 3084**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3085 3086**System capability**: SystemCapability.Account.AppAccount 3087 3088**Parameters** 3089 3090| Name | Type | Mandatory | Description | 3091| ---- | ------ | ---- | ------- | 3092| name | string | Yes | Name of the target app account.| 3093 3094**Return value** 3095 3096| Type | Description | 3097| ---------------------- | --------------------- | 3098| Promise<boolean> | Promise used to return the result. The value **true** means data synchronization is enabled for the app account; the value **false** means the opposite.| 3099 3100**Example** 3101 3102 ```js 3103 appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => { 3104 console.log('checkAppAccountSyncEnable, result: ' + data); 3105 }).catch((err) => { 3106 console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err)); 3107 }); 3108 ``` 3109 3110### setAccountCredential<sup>(deprecated)</sup> 3111 3112setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback<void>): void 3113 3114Set credentials for an app account. This API uses an asynchronous callback to return the result. 3115 3116> **NOTE** 3117> 3118> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9). 3119 3120**System capability**: SystemCapability.Account.AppAccount 3121 3122**Parameters** 3123 3124| Name | Type | Mandatory | Description | 3125| -------------- | ------------------------- | ---- | ------------- | 3126| name | string | Yes | Name of the target app account. | 3127| credentialType | string | Yes | Type of the credential to set. | 3128| credential | string | Yes | Credential value. | 3129| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3130 3131**Example** 3132 3133 ```js 3134 appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => { 3135 console.log("setAccountCredential err: " + JSON.stringify(err)); 3136 }); 3137 ``` 3138 3139### setAccountCredential<sup>(deprecated)</sup> 3140 3141setAccountCredential(name: string, credentialType: string, credential: string): Promise<void> 3142 3143Set credentials for an app account. This API uses a promise to return the result. 3144 3145> **NOTE** 3146> 3147> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCredential](#setcredential9-1). 3148 3149**System capability**: SystemCapability.Account.AppAccount 3150 3151**Parameters** 3152 3153| Name | Type | Mandatory | Description | 3154| -------------- | ------ | ---- | ---------- | 3155| name | string | Yes | Name of the target app account. | 3156| credentialType | string | Yes | Type of the credential to set.| 3157| credential | string | Yes | Credential value.| 3158 3159**Return value** 3160 3161| Type | Description | 3162| :------------------ | :-------------------- | 3163| Promise<void> | Promise that returns no value.| 3164 3165**Example** 3166 3167 ```js 3168 appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => { 3169 console.log('setAccountCredential Success'); 3170 }).catch((err) => { 3171 console.log("setAccountCredential err: " + JSON.stringify(err)); 3172 }); 3173 ``` 3174 3175### setAccountExtraInfo<sup>(deprecated)</sup> 3176 3177setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void 3178 3179Sets additional information for an app account. This API uses an asynchronous callback to return the result. 3180 3181> **NOTE** 3182> 3183> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9). 3184 3185 3186**System capability**: SystemCapability.Account.AppAccount 3187 3188**Parameters** 3189 3190| Name | Type | Mandatory | Description | 3191| --------- | ------------------------- | ---- | --------------- | 3192| name | string | Yes | Name of the target app account. | 3193| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token. | 3194| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3195 3196**Example** 3197 3198 ```js 3199 appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => { 3200 console.log("setAccountExtraInfo err: " + JSON.stringify(err)); 3201 }); 3202 ``` 3203 3204### setAccountExtraInfo<sup>(deprecated)</sup> 3205 3206setAccountExtraInfo(name: string, extraInfo: string): Promise<void> 3207 3208Sets additional information for an app account. This API uses a promise to return the result. 3209 3210> **NOTE** 3211> 3212> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1). 3213 3214 3215**System capability**: SystemCapability.Account.AppAccount 3216 3217**Parameters** 3218 3219| Name | Type | Mandatory | Description | 3220| --------- | ------ | ---- | --------- | 3221| name | string | Yes | Name of the target app account. | 3222| extraInfo | string | Yes | Additional information (information that can be converted to the string type). It cannot contain sensitive information, such as the app account password and token.| 3223 3224**Return value** 3225 3226| Type | Description | 3227| :------------------ | :-------------------- | 3228| Promise<void> | Promise that returns no value.| 3229 3230**Example** 3231 3232 ```js 3233 appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => { 3234 console.log('setAccountExtraInfo Success'); 3235 }).catch((err) => { 3236 console.log("setAccountExtraInfo err: " + JSON.stringify(err)); 3237 }); 3238 ``` 3239 3240### setAppAccountSyncEnable<sup>(deprecated)</sup> 3241 3242setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void 3243 3244Sets data synchronization for an app account. This API uses an asynchronous callback to return the result. 3245 3246> **NOTE** 3247> 3248> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9). 3249 3250**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3251 3252**System capability**: SystemCapability.Account.AppAccount 3253 3254**Parameters** 3255 3256| Name | Type | Mandatory | Description | 3257| -------- | ------------------------- | ---- | ------------------------- | 3258| name | string | Yes | Name of the target app account. | 3259| isEnable | boolean | Yes | Whether to enable data synchronization. | 3260| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3261 3262**Example** 3263 3264 ```js 3265 appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => { 3266 console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); 3267 }); 3268 ``` 3269 3270### setAppAccountSyncEnable<sup>(deprecated)</sup> 3271 3272setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void> 3273 3274Sets data synchronization for an app account. This API uses a promise to return the result. 3275 3276> **NOTE** 3277> 3278> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setDataSyncEnabled](#setdatasyncenabled9-1). 3279 3280**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC 3281 3282**System capability**: SystemCapability.Account.AppAccount 3283 3284**Parameters** 3285 3286| Name | Type | Mandatory | Description | 3287| -------- | ------- | ---- | ----------- | 3288| name | string | Yes | Name of the target app account. | 3289| isEnable | boolean | Yes | Whether to enable data synchronization.| 3290 3291**Return value** 3292 3293| Type | Description | 3294| :------------------ | :-------------------- | 3295| Promise<void> | Promise that returns no value.| 3296 3297**Example** 3298 3299 ```js 3300 appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => { 3301 console.log('setAppAccountSyncEnable Success'); 3302 }).catch((err) => { 3303 console.log("setAppAccountSyncEnable err: " + JSON.stringify(err)); 3304 }); 3305 ``` 3306 3307### setAssociatedData<sup>(deprecated)</sup> 3308 3309setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void 3310 3311Sets data to be associated with an app account. This API uses an asynchronous callback to return the result. 3312 3313> **NOTE** 3314> 3315> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9). 3316 3317 3318**System capability**: SystemCapability.Account.AppAccount 3319 3320**Parameters** 3321 3322| Name | Type | Mandatory | Description | 3323| -------- | ------------------------- | ---- | ----------------- | 3324| name | string | Yes | Name of the target app account. | 3325| key | string | Yes | Key of the data to set.| 3326| value | string | Yes | Value of the data to set. | 3327| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3328 3329**Example** 3330 3331 ```js 3332 appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => { 3333 console.log("setAssociatedData err: " + JSON.stringify(err)); 3334 }); 3335 ``` 3336 3337### setAssociatedData<sup>(deprecated)</sup> 3338 3339setAssociatedData(name: string, key: string, value: string): Promise<void> 3340 3341Sets data to be associated with an app account. This API uses a promise to return the result. 3342 3343> **NOTE** 3344> 3345> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setCustomData](#setcustomdata9-1). 3346 3347 3348**System capability**: SystemCapability.Account.AppAccount 3349 3350**Parameters** 3351 3352| Name | Type | Mandatory | Description | 3353| ----- | ------ | ---- | ----------------- | 3354| name | string | Yes | Name of the target app account. | 3355| key | string | Yes | Key of the data to set.| 3356| value | string | Yes | Value of the data to set.| 3357 3358**Return value** 3359 3360| Type | Description | 3361| :------------------ | :-------------------- | 3362| Promise<void> | Promise that returns no value.| 3363 3364**Example** 3365 3366 ```js 3367 appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => { 3368 console.log('setAssociatedData Success'); 3369 }).catch((err) => { 3370 console.log("setAssociatedData err: " + JSON.stringify(err)); 3371 }); 3372 ``` 3373 3374### getAllAccessibleAccounts<sup>(deprecated)</sup> 3375 3376getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void 3377 3378Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result. 3379 3380> **NOTE** 3381> 3382> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9). 3383 3384**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS 3385 3386**System capability**: SystemCapability.Account.AppAccount 3387 3388**Parameters** 3389 3390| Name | Type | Mandatory | Description | 3391| -------- | ---------------------------------------- | ---- | --------- | 3392| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of accessible app accounts. Otherwise, **err** is an error object.| 3393 3394**Example** 3395 3396 ```js 3397 appAccountManager.getAllAccessibleAccounts((err, data)=>{ 3398 console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err)); 3399 console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data)); 3400 }); 3401 ``` 3402 3403### getAllAccessibleAccounts<sup>(deprecated)</sup> 3404 3405getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>> 3406 3407Obtains information about all accessible app accounts. This API uses a promise to return the result. 3408 3409> **NOTE** 3410> 3411> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAllAccounts](#getallaccounts9-1). 3412 3413**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS 3414 3415**System capability**: SystemCapability.Account.AppAccount 3416 3417**Return value** 3418 3419| Type | Description | 3420| ---------------------------------------- | --------------------- | 3421| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise used to return the accessible app accounts.| 3422 3423**Example** 3424 3425 ```js 3426 appAccountManager.getAllAccessibleAccounts().then((data) => { 3427 console.log('getAllAccessibleAccounts: ' + data); 3428 }).catch((err) => { 3429 console.log("getAllAccessibleAccounts err: " + JSON.stringify(err)); 3430 }); 3431 ``` 3432 3433### getAllAccounts<sup>(deprecated)</sup> 3434 3435getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void 3436 3437Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses an asynchronous callback to return the result. 3438 3439> **NOTE** 3440> 3441> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9). 3442 3443**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS 3444 3445**System capability**: SystemCapability.Account.AppAccount 3446 3447**Parameters** 3448 3449| Name | Type | Mandatory | Description | 3450| -------- | ---------------------------------------- | ---- | --------- | 3451| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3452| callback | AsyncCallback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return information about all accessible app accounts.| 3453 3454**Example** 3455 3456 ```js 3457 const selfBundle = "com.example.actsgetallaaccounts"; 3458 appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ 3459 console.debug("getAllAccounts err:" + JSON.stringify(err)); 3460 console.debug("getAllAccounts data:" + JSON.stringify(data)); 3461 }); 3462 ``` 3463 3464### getAllAccounts<sup>(deprecated)</sup> 3465 3466getAllAccounts(owner: string): Promise<Array<AppAccountInfo>> 3467 3468Obtains the app accounts that can be accessed by the invoker based on the app account owner. This API uses a promise to return the result. 3469 3470> **NOTE** 3471> 3472> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getAccountsByOwner](#getaccountsbyowner9-1). 3473 3474**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications) 3475 3476**System capability**: SystemCapability.Account.AppAccount 3477 3478**Parameters** 3479 3480| Name | Type | Mandatory | Description | 3481| ----- | ------ | ---- | ------ | 3482| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 3483 3484**Return value** 3485 3486| Type | Description | 3487| ---------------------------------------- | --------------------- | 3488| Promise<Array<[AppAccountInfo](#appaccountinfo)>> | Promise use to return the app accounts that can be accessed by the invoker.| 3489 3490**Example** 3491 3492 ```js 3493 const selfBundle = "com.example.actsgetallaaccounts"; 3494 appAccountManager.getAllAccounts(selfBundle).then((data) => { 3495 console.log('getAllAccounts: ' + data); 3496 }).catch((err) => { 3497 console.log("getAllAccounts err: " + JSON.stringify(err)); 3498 }); 3499 ``` 3500 3501### getAccountCredential<sup>(deprecated)</sup> 3502 3503getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void 3504 3505Obtains the credential of an app account. This API uses an asynchronous callback to return the result. 3506 3507> **NOTE** 3508> 3509> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9). 3510 3511**System capability**: SystemCapability.Account.AppAccount 3512 3513**Parameters** 3514 3515| Name | Type | Mandatory | Description | 3516| -------------- | --------------------------- | ---- | -------------- | 3517| name | string | Yes | Name of the target app account. | 3518| credentialType | string | Yes | Type of the credential to obtain.| 3519| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the credential obtained. Otherwise, **err** is an error object.| 3520 3521**Example** 3522 3523 ```js 3524 appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => { 3525 console.log("getAccountCredential err: " + JSON.stringify(err)); 3526 console.log('getAccountCredential result: ' + result); 3527 }); 3528 ``` 3529 3530### getAccountCredential<sup>(deprecated)</sup> 3531 3532getAccountCredential(name: string, credentialType: string): Promise<string> 3533 3534Obtains the credential of an app account. This API uses a promise to return the result. 3535 3536> **NOTE** 3537> 3538> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCredential](#getcredential9-1). 3539 3540**System capability**: SystemCapability.Account.AppAccount 3541 3542**Parameters** 3543 3544| Name | Type | Mandatory | Description | 3545| -------------- | ------ | ---- | ---------- | 3546| name | string | Yes | Name of the target app account. | 3547| credentialType | string | Yes | Type of the credential to obtain.| 3548 3549**Return value** 3550 3551| Type | Description | 3552| :-------------------- | :-------------------- | 3553| Promise<string> | Promise used to return the credential obtained.| 3554 3555**Example** 3556 3557 ```js 3558 appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => { 3559 console.log('getAccountCredential, result: ' + data); 3560 }).catch((err) => { 3561 console.log("getAccountCredential err: " + JSON.stringify(err)); 3562 }); 3563 ``` 3564 3565### getAccountExtraInfo<sup>(deprecated)</sup> 3566 3567getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void 3568 3569Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses an asynchronous callback to return the result. 3570 3571> **NOTE** 3572> 3573> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9). 3574 3575**System capability**: SystemCapability.Account.AppAccount 3576 3577**Parameters** 3578 3579| Name | Type | Mandatory | Description | 3580| -------- | --------------------------- | ---- | --------------- | 3581| name | string | Yes | Name of the target app account. | 3582| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the additional information obtained. Otherwise, **err** is an error object.| 3583 3584**Example** 3585 3586 ```js 3587 appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => { 3588 console.log("getAccountExtraInfo err: " + JSON.stringify(err)); 3589 console.log('getAccountExtraInfo result: ' + result); 3590 }); 3591 ``` 3592 3593### getAccountExtraInfo<sup>(deprecated)</sup> 3594 3595getAccountExtraInfo(name: string): Promise<string> 3596 3597Obtains additional information of an app account. Additional information refers to other information that can be converted to the string type. It cannot contain sensitive information, such as the app account password and token. This API uses a promise to return the result. 3598 3599> **NOTE** 3600> 3601> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1). 3602 3603**System capability**: SystemCapability.Account.AppAccount 3604 3605**Parameters** 3606 3607| Name | Type | Mandatory | Description | 3608| ---- | ------ | ---- | ------- | 3609| name | string | Yes | Name of the target app account.| 3610 3611**Return value** 3612 3613| Type | Description | 3614| :-------------------- | :-------------------- | 3615| Promise<string> | Promise used to return the additional information obtained.| 3616 3617**Example** 3618 3619 ```js 3620 appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => { 3621 console.log('getAccountExtraInfo, result: ' + data); 3622 }).catch((err) => { 3623 console.log("getAccountExtraInfo err: " + JSON.stringify(err)); 3624 }); 3625 ``` 3626 3627### getAssociatedData<sup>(deprecated)</sup> 3628 3629getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void 3630 3631Obtains data associated with an app account. This API uses an asynchronous callback to return the result. 3632 3633> **NOTE** 3634> 3635> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9). 3636 3637**System capability**: SystemCapability.Account.AppAccount 3638 3639**Parameters** 3640 3641| Name | Type | Mandatory | Description | 3642| -------- | --------------------------- | ---- | ----------------- | 3643| name | string | Yes | Name of the target app account. | 3644| key | string | Yes | Key of the data to obtain. | 3645| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the data obtained. Otherwise, **err** is an error object.| 3646 3647**Example** 3648 3649 ```js 3650 appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => { 3651 console.log("getAssociatedData err: " + JSON.stringify(err)); 3652 console.log('getAssociatedData result: ' + result); 3653 }); 3654 ``` 3655 3656### getAssociatedData<sup>(deprecated)</sup> 3657 3658getAssociatedData(name: string, key: string): Promise<string> 3659 3660Obtains data associated with an app account. This API uses a promise to return the result. 3661 3662> **NOTE** 3663> 3664> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getCustomData](#getcustomdata9-1). 3665 3666**System capability**: SystemCapability.Account.AppAccount 3667 3668**Parameters** 3669 3670| Name | Type | Mandatory | Description | 3671| ---- | ------ | ---- | --------- | 3672| name | string | Yes | Name of the target app account. | 3673| key | string | Yes | Key of the data to obtain.| 3674 3675**Return value** 3676 3677| Type | Description | 3678| :-------------------- | :-------------------- | 3679| Promise<string> | Promise used to return the data obtained.| 3680 3681**Example** 3682 3683 ```js 3684 appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => { 3685 console.log('getAssociatedData: ' + data); 3686 }).catch((err) => { 3687 console.log("getAssociatedData err: " + JSON.stringify(err)); 3688 }); 3689 ``` 3690 3691### on('change')<sup>(deprecated)</sup> 3692 3693on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void 3694 3695Subscribes to account information changes of apps. 3696 3697> **NOTE** 3698> 3699> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [on('accountChange')](#onaccountchange9). 3700 3701**System capability**: SystemCapability.Account.AppAccount 3702 3703**Parameters** 3704 3705| Name | Type | Mandatory | Description | 3706| -------- | ---------------------------------------- | ---- | ------------------------------ | 3707| type | 'change' | Yes | Event type to subscribe to. The value is **'change'**. An event will be reported when the account information changes.| 3708| owners | Array<string> | Yes | App bundle names of the account. | 3709| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | Yes | Callback invoked to return the account changes. | 3710 3711**Example** 3712 3713 ```js 3714 function changeOnCallback(data){ 3715 console.debug("receive change data:" + JSON.stringify(data)); 3716 } 3717 try{ 3718 appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); 3719 } 3720 catch(err){ 3721 console.error("on accountOnOffDemo err:" + JSON.stringify(err)); 3722 } 3723 ``` 3724 3725### off('change')<sup>(deprecated)</sup> 3726 3727off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void 3728 3729Unsubscribes from account information changes. 3730 3731> **NOTE** 3732> 3733> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [off('accountChange')](#offaccountchange9). 3734 3735**System capability**: SystemCapability.Account.AppAccount 3736 3737**Parameters** 3738 3739| Name | Type | Mandatory | Description | 3740| -------- | -------------------------------- | ---- | ------------ | 3741| type | 'change' | Yes | Event type to unsubscribe from. The value is **'change'**, which indicates the account change event. | 3742| callback | Callback<Array<[AppAccountInfo](#appaccountinfo)>> | No | Callback to unregister.| 3743 3744**Example** 3745 3746 ```js 3747 function changeOnCallback(data){ 3748 console.debug("receive change data:" + JSON.stringify(data)); 3749 appAccountManager.off('change', function(){ 3750 console.debug("off finish"); 3751 }) 3752 } 3753 try{ 3754 appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback); 3755 } 3756 catch(err){ 3757 console.error("on accountOnOffDemo err:" + JSON.stringify(err)); 3758 } 3759 ``` 3760 3761### authenticate<sup>(deprecated)</sup> 3762 3763authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void 3764 3765Authenticates an app account with customized options. This API uses an asynchronous callback to return the result. 3766 3767> **NOTE** 3768> 3769> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9). 3770 3771**System capability**: SystemCapability.Account.AppAccount 3772 3773**Parameters** 3774 3775| Name | Type | Mandatory | Description | 3776| -------- | --------------------- | ---- | --------------- | 3777| name | string | Yes | Name of the target app account. | 3778| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3779| authType | string | Yes | Authentication type. | 3780| options | {[key: string]: any} | Yes | Options for the authentication. | 3781| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Callback invoked to return the result.| 3782 3783**Example** 3784 3785 ```js 3786 function onResultCallback(code, result) { 3787 console.log("resultCode: " + code); 3788 console.log("result: " + JSON.stringify(result)); 3789 } 3790 3791 function onRequestRedirectedCallback(request) { 3792 let wantInfo = { 3793 deviceId: '', 3794 bundleName: 'com.example.accountjsdemo', 3795 action: 'ohos.want.action.viewData', 3796 entities: ['entity.system.default'], 3797 } 3798 this.context.startAbility(wantInfo).then(() => { 3799 console.log("startAbility successfully"); 3800 }).catch((err) => { 3801 console.log("startAbility err: " + JSON.stringify(err)); 3802 }) 3803 } 3804 3805 appAccountManager.authenticate("LiSi", "com.example.accountjsdemo", "getSocialData", {}, { 3806 onResult: onResultCallback, 3807 onRequestRedirected: onRequestRedirectedCallback 3808 }); 3809 ``` 3810 3811### getOAuthToken<sup>(deprecated)</sup> 3812 3813getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void 3814 3815Obtains the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 3816 3817> **NOTE** 3818> 3819> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9). 3820 3821**System capability**: SystemCapability.Account.AppAccount 3822 3823**Parameters** 3824 3825| Name | Type | Mandatory | Description | 3826| -------- | --------------------------- | ---- | ----------- | 3827| name | string | Yes | Name of the target app account. | 3828| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 3829| authType | string | Yes | Authentication type. | 3830| callback | AsyncCallback<string> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authorization token value obtained. Otherwise, **err** is an error object. | 3831 3832**Example** 3833 3834 ```js 3835 appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", (err, data) => { 3836 console.log('getOAuthToken err: ' + JSON.stringify(err)); 3837 console.log('getOAuthToken token: ' + data); 3838 }); 3839 ``` 3840 3841### getOAuthToken<sup>(deprecated)</sup> 3842 3843getOAuthToken(name: string, owner: string, authType: string): Promise<string> 3844 3845Obtains the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 3846 3847> **NOTE** 3848> 3849> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthToken](#getauthtoken9-1). 3850 3851**System capability**: SystemCapability.Account.AppAccount 3852 3853**Parameters** 3854 3855| Name | Type | Mandatory | Description | 3856| -------- | ------ | ---- | ----------- | 3857| name | string | Yes | Name of the target app account. | 3858| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 3859| authType | string | Yes | Authentication type. | 3860 3861**Return value** 3862 3863| Type | Description | 3864| --------------------- | --------------------- | 3865| Promise<string> | Promise used to return the result.| 3866 3867**Example** 3868 3869 ```js 3870 appAccountManager.getOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData").then((data) => { 3871 console.log('getOAuthToken token: ' + data); 3872 }).catch((err) => { 3873 console.log("getOAuthToken err: " + JSON.stringify(err)); 3874 }); 3875 ``` 3876 3877### setOAuthToken<sup>(deprecated)</sup> 3878 3879setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void 3880 3881Sets an authorization token of the specific authentication type for an app account. This API uses an asynchronous callback to return the result. 3882 3883> **NOTE** 3884> 3885> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9). 3886 3887**System capability**: SystemCapability.Account.AppAccount 3888 3889**Parameters** 3890 3891| Name | Type | Mandatory | Description | 3892| -------- | ------------------------- | ---- | -------- | 3893| name | string | Yes | Name of the target app account.| 3894| authType | string | Yes | Authentication type. | 3895| token | string | Yes | Token to set.| 3896| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 3897 3898**Example** 3899 3900 ```js 3901 appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => { 3902 console.log('setOAuthToken err: ' + JSON.stringify(err)); 3903 }); 3904 ``` 3905 3906### setOAuthToken<sup>(deprecated)</sup> 3907 3908setOAuthToken(name: string, authType: string, token: string): Promise<void> 3909 3910Sets an authorization token of the specific authentication type for an app account. This API uses a promise to return the result. 3911 3912> **NOTE** 3913> 3914> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthToken](#setauthtoken9-1). 3915 3916**System capability**: SystemCapability.Account.AppAccount 3917 3918**Parameters** 3919 3920| Name | Type | Mandatory | Description | 3921| -------- | ------ | ---- | -------- | 3922| name | string | Yes | Name of the target app account.| 3923| authType | string | Yes | Authentication type. | 3924| token | string | Yes | Authorization token to set.| 3925 3926**Return value** 3927 3928| Type | Description | 3929| ------------------- | --------------------- | 3930| Promise<void> | Promise that returns no value.| 3931 3932**Example** 3933 3934 ```js 3935 appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => { 3936 console.log('setOAuthToken successfully'); 3937 }).catch((err) => { 3938 console.log('setOAuthToken err: ' + JSON.stringify(err)); 3939 }); 3940 ``` 3941 3942### deleteOAuthToken<sup>(deprecated)</sup> 3943 3944deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void 3945 3946Deletes the authorization token of the specified authentication type for an app account. This API uses an asynchronous callback to return the result. 3947 3948> **NOTE** 3949> 3950> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9). 3951 3952**System capability**: SystemCapability.Account.AppAccount 3953 3954**Parameters** 3955 3956| Name | Type | Mandatory | Description | 3957| -------- | ------------------------- | ---- | ------------ | 3958| name | string | Yes | Name of the target app account. | 3959| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3960| authType | string | Yes | Authentication type. | 3961| token | string | Yes | Authorization token to delete.| 3962| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 3963 3964**Example** 3965 3966 ```js 3967 appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx", (err) => { 3968 console.log('deleteOAuthToken err: ' + JSON.stringify(err)); 3969 }); 3970 ``` 3971 3972### deleteOAuthToken<sup>(deprecated)</sup> 3973 3974deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void> 3975 3976Deletes the authorization token of the specified authentication type for an app account. This API uses a promise to return the result. 3977 3978> **NOTE** 3979> 3980> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteAuthToken](#deleteauthtoken9-1). 3981 3982**System capability**: SystemCapability.Account.AppAccount 3983 3984**Parameters** 3985 3986| Name | Type | Mandatory | Description | 3987| -------- | ------ | ---- | ------------ | 3988| name | string | Yes | Name of the target app account. | 3989| owner | string | Yes | Owner of the app account. The value is the bundle name of the app. | 3990| authType | string | Yes | Authentication type. | 3991| token | string | Yes | Authorization token to delete.| 3992 3993**Return value** 3994 3995| Type | Description | 3996| ------------------- | --------------------- | 3997| Promise<void> | Promise that returns no value.| 3998 3999**Example** 4000 4001 ```js 4002 appAccountManager.deleteOAuthToken("LiSi", "com.example.accountjsdemo", "getSocialData", "xxxxx").then(() => { 4003 console.log('deleteOAuthToken successfully'); 4004 }).catch((err) => { 4005 console.log("deleteOAuthToken err: " + JSON.stringify(err)); 4006 }); 4007 ``` 4008 4009### setOAuthTokenVisibility<sup>(deprecated)</sup> 4010 4011setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void 4012 4013Sets the visibility of an authorization token to an app. This API uses an asynchronous callback to return the result. 4014 4015> **NOTE** 4016> 4017> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9). 4018 4019**System capability**: SystemCapability.Account.AppAccount 4020 4021**Parameters** 4022 4023| Name | Type | Mandatory | Description | 4024| ---------- | ------------------------- | ---- | ------------------------- | 4025| name | string | Yes | Name of the target app account. | 4026| authType | string | Yes | Authentication type. | 4027| bundleName | string | Yes | Bundle name of the app. | 4028| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| 4029| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 4030 4031**Example** 4032 4033 ```js 4034 appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true, (err) => { 4035 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4036 }); 4037 ``` 4038 4039### setOAuthTokenVisibility<sup>(deprecated)</sup> 4040 4041setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void> 4042 4043Sets the visibility of an authorization token to an app. This API uses a promise to return the result. 4044 4045> **NOTE** 4046> 4047> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setAuthTokenVisibility](#setauthtokenvisibility9-1). 4048 4049**System capability**: SystemCapability.Account.AppAccount 4050 4051**Parameters** 4052 4053| Name | Type | Mandatory | Description | 4054| ---------- | ------- | ---- | ------------ | 4055| name | string | Yes | Name of the target app account. | 4056| authType | string | Yes | Authentication type. | 4057| bundleName | string | Yes | Bundle name of the app.| 4058| isVisible | boolean | Yes | Whether the authorization token is visible to the app. The value **true** means the authorization token is visible to the app; the value **false** means the opposite. | 4059 4060**Return value** 4061 4062| Type | Description | 4063| ------------------- | --------------------- | 4064| Promise<void> | Promise that returns no value.| 4065 4066**Example** 4067 4068 ```js 4069 appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", true).then(() => { 4070 console.log('setOAuthTokenVisibility successfully'); 4071 }).catch((err) => { 4072 console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err)); 4073 }); 4074 ``` 4075 4076### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4077 4078checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void 4079 4080Checks the visibility of an authorization token of the specified authentication type to an app. This API uses an asynchronous callback to return the result. 4081 4082> **NOTE** 4083> 4084> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9). 4085 4086**System capability**: SystemCapability.Account.AppAccount 4087 4088**Parameters** 4089 4090| Name | Type | Mandatory | Description | 4091| ---------- | ---------------------------- | ---- | ----------- | 4092| name | string | Yes | Name of the target app account. | 4093| authType | string | Yes | Authentication type. | 4094| bundleName | string | Yes | Bundle name of the app.| 4095| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** can be **true** (the authorization token is visible to the app) or **false** (the authorization token is not visible to the app). If the operation fails, **err** is an error object. | 4096 4097**Example** 4098 4099 ```js 4100 appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo", (err, data) => { 4101 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4102 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4103 }); 4104 ``` 4105 4106### checkOAuthTokenVisibility<sup>(deprecated)</sup> 4107 4108checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean> 4109 4110Checks the visibility of an authorization token of the specified authentication type to an app. This API uses a promise to return the result. 4111 4112> **NOTE** 4113> 4114> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [checkAuthTokenVisibility](#checkauthtokenvisibility9-1). 4115 4116**System capability**: SystemCapability.Account.AppAccount 4117 4118**Parameters** 4119 4120| Name | Type | Mandatory | Description | 4121| ---------- | ------ | ---- | ------------- | 4122| name | string | Yes | Name of the target app account. | 4123| authType | string | Yes | Authentication type. | 4124| bundleName | string | Yes | Bundle name of the app.| 4125 4126**Return value** 4127 4128| Type | Description | 4129| ---------------------- | --------------------- | 4130| Promise<boolean> | Promise used to return the result. The value **true** means the authorization token is visible to the app; the value **false** means the opposite.| 4131 4132**Example** 4133 4134 ```js 4135 appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.accountjsdemo").then((data) => { 4136 console.log('checkOAuthTokenVisibility isVisible: ' + data); 4137 }).catch((err) => { 4138 console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err)); 4139 }); 4140 ``` 4141 4142### getAllOAuthTokens<sup>(deprecated)</sup> 4143 4144getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void 4145 4146Obtains all tokens visible to the invoker for an app account. This API uses an asynchronous callback to return the result. 4147 4148> **NOTE** 4149> 4150> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9). 4151 4152**System capability**: SystemCapability.Account.AppAccount 4153 4154**Parameters** 4155 4156| Name | Type | Mandatory | Description | 4157| -------- | ---------------------------------------- | ---- | ----------- | 4158| name | string | Yes | Name of the target app account. | 4159| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 4160| callback | AsyncCallback<Array<[OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of all tokens visible to the invoker. Otherwise, **err** is an error object. | 4161 4162**Example** 4163 4164 ```js 4165 appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo", (err, data) => { 4166 console.log("getAllOAuthTokens err: " + JSON.stringify(err)); 4167 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4168 }); 4169 ``` 4170 4171### getAllOAuthTokens<sup>(deprecated)</sup> 4172 4173getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>> 4174 4175Obtains all tokens visible to the invoker for an app account. This API uses a promise to return the result. 4176 4177> **NOTE** 4178> 4179> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAllAuthTokens](#getallauthtokens9-1). 4180 4181**System capability**: SystemCapability.Account.AppAccount 4182 4183**Parameters** 4184 4185| Name | Type | Mandatory | Description | 4186| ----- | ------ | ---- | ----------- | 4187| name | string | Yes | Name of the target app account. | 4188| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 4189 4190**Return value** 4191 4192| Type | Description | 4193| ---------------------------------------- | --------------------- | 4194| Promise<Array< [OAuthTokenInfo](#oauthtokeninfodeprecated)>> | Promise used to return the tokens obtained.| 4195 4196**Example** 4197 4198 ```js 4199 appAccountManager.getAllOAuthTokens("LiSi", "com.example.accountjsdemo").then((data) => { 4200 console.log('getAllOAuthTokens data: ' + JSON.stringify(data)); 4201 }).catch((err) => { 4202 console.log("getAllOAuthTokens err: " + JSON.stringify(err)); 4203 }); 4204 ``` 4205 4206### getOAuthList<sup>(deprecated)</sup> 4207 4208getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void 4209 4210Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses an asynchronous callback to return the result. 4211 4212> **NOTE** 4213> 4214> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9). 4215 4216**System capability**: SystemCapability.Account.AppAccount 4217 4218**Parameters** 4219 4220| Name | Type | Mandatory | Description | 4221| -------- | ---------------------------------------- | ---- | ----------------------- | 4222| name | string | Yes | Name of the target app account. | 4223| authType | string | Yes | Authentication type.| 4224| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is a list of authorized bundles obtained. Otherwise, **err** is an error object. | 4225 4226**Example** 4227 4228 ```js 4229 appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData", (err, data) => { 4230 console.log('getOAuthList err: ' + JSON.stringify(err)); 4231 console.log('getOAuthList data: ' + JSON.stringify(data)); 4232 }); 4233 ``` 4234 4235### getOAuthList<sup>(deprecated)</sup> 4236 4237getOAuthList(name: string, authType: string): Promise<Array<string>> 4238 4239Obtains the authorization list of the specified authentication type for an app account. The authorization list contains all authorized bundles. The token authorization list is set by setOAuthTokenVisibility(#setoauthtokenvisibilitydeprecated). This API uses a promise to return the result. 4240 4241> **NOTE** 4242> 4243> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthList](#getauthlist9-1). 4244 4245**System capability**: SystemCapability.Account.AppAccount 4246 4247**Parameters** 4248 4249| Name | Type | Mandatory | Description | 4250| -------- | ------ | ---- | ----------------------- | 4251| name | string | Yes | Name of the target app account. | 4252| authType | string | Yes | Authentication type.| 4253 4254**Return value** 4255 4256| Type | Description | 4257| ---------------------------------- | --------------------- | 4258| Promise<Array<string>> | Promise used to return a list of authorized bundles.| 4259 4260**Example** 4261 4262 ```js 4263 appAccountManager.getOAuthList("com.example.accountjsdemo", "getSocialData").then((data) => { 4264 console.log('getOAuthList data: ' + JSON.stringify(data)); 4265 }).catch((err) => { 4266 console.log("getOAuthList err: " + JSON.stringify(err)); 4267 }); 4268 ``` 4269 4270### getAuthenticatorCallback<sup>(deprecated)</sup> 4271 4272getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void 4273 4274Obtains the authenticator callback for an authentication session. This API uses an asynchronous callback to return the result. 4275 4276> **NOTE** 4277> 4278> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9). 4279 4280**System capability**: SystemCapability.Account.AppAccount 4281 4282**Parameters** 4283 4284| Name | Type | Mandatory | Description | 4285| --------- | ---------------------------------------- | ---- | -------- | 4286| sessionId | string | Yes | ID of the authentication session.| 4287| callback | AsyncCallback<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator callback obtained. Otherwise, **err** is an error object.| 4288 4289**Example** 4290 4291 ```js 4292 import featureAbility from '@ohos.ability.featureAbility'; 4293 featureAbility.getWant((err, want) => { 4294 var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; 4295 appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => { 4296 if (err.code != account_appAccount.ResultCode.SUCCESS) { 4297 console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); 4298 return; 4299 } 4300 var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", 4301 [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", 4302 [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", 4303 [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; 4304 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4305 }); 4306 }); 4307 ``` 4308 4309### getAuthenticatorCallback<sup>(deprecated)</sup> 4310 4311getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback> 4312 4313Obtains the authenticator callback for an authentication session. This API uses a promise to return the result. 4314 4315> **NOTE** 4316> 4317> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getAuthCallback](#getauthcallback9-1). 4318 4319**System capability**: SystemCapability.Account.AppAccount 4320 4321**Parameters** 4322 4323| Name | Type | Mandatory | Description | 4324| --------- | ------ | ---- | -------- | 4325| sessionId | string | Yes | ID of the authentication session.| 4326 4327**Return value** 4328 4329| Type | Description | 4330| ------------------------------------ | --------------------- | 4331| Promise<[AuthenticatorCallback](#authenticatorcallbackdeprecated)> | Promise used to return the authenticator callback obtained.| 4332 4333**Example** 4334 4335 ```js 4336 import featureAbility from '@ohos.ability.featureAbility'; 4337 4338 featureAbility.getWant().then((want) => { 4339 var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID]; 4340 appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { 4341 var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", 4342 [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", 4343 [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", 4344 [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; 4345 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4346 }).catch((err) => { 4347 console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); 4348 }); 4349 }).catch((err) => { 4350 console.log("getWant err: " + JSON.stringify(err)); 4351 }); 4352 ``` 4353 4354### getAuthenticatorInfo<sup>(deprecated)</sup> 4355 4356getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void 4357 4358Obtains the authenticator information of an app. This API uses an asynchronous callback to return the result. 4359 4360> **NOTE** 4361> 4362> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9). 4363 4364**System capability**: SystemCapability.Account.AppAccount 4365 4366**Parameters** 4367 4368| Name | Type | Mandatory | Description | 4369| -------- | -------------------------------------- | ---- | ----------- | 4370| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 4371| callback | AsyncCallback<[AuthenticatorInfo](#authenticatorinfo8)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null** and **data** is the authenticator information obtained. Otherwise, **err** is an error object. | 4372 4373**Example** 4374 4375 ```js 4376 appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo", (err, data) => { 4377 console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); 4378 console.log('getAuthenticatorInfo data: ' + JSON.stringify(data)); 4379 }); 4380 ``` 4381 4382### getAuthenticatorInfo<sup>(deprecated)</sup> 4383 4384getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> 4385 4386Obtains the authenticator information of an app. This API uses a promise to return the result. 4387 4388> **NOTE** 4389> 4390> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [queryAuthenticatorInfo](#queryauthenticatorinfo9-1). 4391 4392**System capability**: SystemCapability.Account.AppAccount 4393 4394**Parameters** 4395 4396| Name | Type | Mandatory | Description | 4397| ----- | ------ | ---- | ----------- | 4398| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 4399 4400**Return value** 4401 4402| Type | Description | 4403| -------------------------------- | --------------------- | 4404| Promise<[AuthenticatorInfo](#authenticatorinfo8)> | Promise used to return the authenticator information obtained.| 4405 4406**Example** 4407 4408 ```js 4409 appAccountManager.getAuthenticatorInfo("com.example.accountjsdemo").then((data) => { 4410 console.log('getAuthenticatorInfo: ' + JSON.stringify(data)); 4411 }).catch((err) => { 4412 console.log("getAuthenticatorInfo err: " + JSON.stringify(err)); 4413 }); 4414 ``` 4415 4416## AppAccountInfo 4417 4418Defines app account information. 4419 4420**System capability**: SystemCapability.Account.AppAccount 4421 4422| Name | Type | Mandatory | Description | 4423| ----- | ------ | ---- | ----------- | 4424| owner | string | Yes | Owner of the app account. The value is the bundle name of the app.| 4425| name | string | Yes | Name of the target app account. | 4426 4427## AuthTokenInfo<sup>9+</sup> 4428 4429Defines authorization token information. 4430 4431**System capability**: SystemCapability.Account.AppAccount 4432 4433| Name | Type | Mandatory | Description | 4434| -------------------- | -------------- | ----- | ---------------- | 4435| authType<sup>9+</sup> | string | Yes | Authentication type. | 4436| token<sup>9+</sup> | string | Yes | Value of the authorization token. | 4437| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| 4438 4439## OAuthTokenInfo<sup>(deprecated)</sup> 4440 4441Defines authorization token information. 4442 4443> **NOTE** 4444> 4445> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthTokenInfo](#authtokeninfo9). 4446 4447**System capability**: SystemCapability.Account.AppAccount 4448 4449| Name | Type | Mandatory | Description | 4450| -------------------- | -------------- | ----- | ---------------- | 4451| authType | string | Yes | Authentication type. | 4452| token | string | Yes | Value of the authorization token. | 4453| account<sup>9+</sup> | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| 4454 4455## AuthenticatorInfo<sup>8+</sup> 4456 4457Defines OAuth authenticator information. 4458 4459**System capability**: SystemCapability.Account.AppAccount 4460 4461| Name | Type | Mandatory | Description | 4462| ------- | ------ | ---- | ---------- | 4463| owner | string | Yes | Owner of the authenticator. The value is the bundle name of the app.| 4464| iconId | number | Yes | ID of the authenticator icon. | 4465| labelId | number | Yes | ID of the authenticator label. | 4466 4467## AuthResult<sup>9+</sup> 4468 4469Defines the authentication result. 4470 4471**System capability**: SystemCapability.Account.AppAccount 4472 4473| Name | Type | Mandatory | Description | 4474| ------- | ------ | ---- | ---------- | 4475| account | [AppAccountInfo](#appaccountinfo) | No | Account information of the authorization token.| 4476| tokenInfo | [AuthTokenInfo](#authtokeninfo9) | No | Token information. | 4477 4478## CreateAccountOptions<sup>9+</sup> 4479 4480Defines the options for creating an app account. 4481 4482**System capability**: SystemCapability.Account.AppAccount 4483 4484| Name | Type | Mandatory | Description | 4485| ------- | ------ | ---- | ---------- | 4486| customData | {[key: string]: string} | No | Custom data.| 4487 4488## CreateAccountImplicitlyOptions<sup>9+</sup> 4489 4490Defines the options for implicitly creating an app account. 4491 4492**System capability**: SystemCapability.Account.AppAccount 4493 4494| Name | Type | Mandatory | Description | 4495| ------- | ------ | ---- | ---------- | 4496| requiredLabels | Array<string> | No | Labels required.| 4497| authType | string | No | Authentication type.| 4498| parameters | {[key: string]: Object} | No | Customized parameters.| 4499## SelectAccountsOptions<sup>9+</sup> 4500 4501Defines the options for selecting accounts. 4502 4503**System capability**: SystemCapability.Account.AppAccount 4504 4505| Name | Type | Mandatory | Description | 4506| --------------- | --------------------------- | ----- | ------------------- | 4507| allowedAccounts | Array<[AppAccountInfo](#appaccountinfo)> | No | Allowed accounts. | 4508| allowedOwners | Array<string> | No | Allowed account owners.| 4509| requiredLabels | Array<string> | No | Labels required for the authenticator. | 4510 4511## VerifyCredentialOptions<sup>9+</sup> 4512 4513Represents the options for verifying the user credential. 4514 4515**System capability**: SystemCapability.Account.AppAccount 4516 4517| Name | Type | Mandatory | Description | 4518| -------------- | ---------------------- | ----- | -------------- | 4519| credentialType | string | No | Type of the credential to verify. | 4520| credential | string | No | Credential value. | 4521| parameters | {[key: string]: Object} | No | Customized parameters.| 4522 4523 4524## SetPropertiesOptions<sup>9+</sup> 4525 4526Represents the options for setting authenticator properties. 4527 4528**System capability**: SystemCapability.Account.AppAccount 4529 4530| Name | Type | Mandatory | Description | 4531| ---------- | ---------------------- | ----- | -------------- | 4532| properties | {[key: string]: Object} | No | Authenticator properties. | 4533| parameters | {[key: string]: Object} | No | Customized parameters.| 4534 4535## Constants<sup>8+</sup> 4536 4537Enumerates the constants. 4538 4539**System capability**: SystemCapability.Account.AppAccount 4540 4541| Name | Value | Description | 4542| -------------------------------- | ---------------------- | ----------------------- | 4543| ACTION_ADD_ACCOUNT_IMPLICITLY<sup>(deprecated)</sup> | "addAccountImplicitly" | Operation of adding an account implicitly. | 4544| ACTION_AUTHENTICATE<sup>(deprecated)</sup> | "authenticate" | Authentication operation. | 4545| ACTION_CREATE_ACCOUNT_IMPLICITLY<sup>9+</sup> | "createAccountImplicitly" | Operation of creating an account implicitly. | 4546| ACTION_AUTH<sup>9+</sup> | "auth" | Authentication operation. | 4547| ACTION_VERIFY_CREDENTIAL<sup>9+</sup> | "verifyCredential" | Operation of verifying credentials. | 4548| ACTION_SET_AUTHENTICATOR_PROPERTIES<sup>9+</sup> | "setAuthenticatorProperties" | Operation of setting authenticator properties. | 4549| KEY_NAME | "name" | Name of the app account. | 4550| KEY_OWNER | "owner" | Owner of the app account.| 4551| KEY_TOKEN | "token" | Token. | 4552| KEY_ACTION | "action" | Operation. | 4553| KEY_AUTH_TYPE | "authType" | Authentication type. | 4554| KEY_SESSION_ID | "sessionId" | Session ID. | 4555| KEY_CALLER_PID | "callerPid" | PID of the caller. | 4556| KEY_CALLER_UID | "callerUid" | UID of the caller. | 4557| KEY_CALLER_BUNDLE_NAME | "callerBundleName" | Bundle name of the caller. | 4558| KEY_REQUIRED_LABELS<sup>9+</sup> | "requiredLabels" | Required labels. | 4559| KEY_BOOLEAN_RESULT<sup>9+</sup> | "booleanResult" | Return value of the Boolean type. | 4560 4561## ResultCode<sup>(deprecated)</sup> 4562 4563Enumerates the result codes. 4564 4565> **NOTE**<br> 4566> This enum is supported since API version 8 and deprecated since API version 9. Error codes are used from API version 9. For details, see [Account Management Error Codes](../errorcodes/errorcode-account.md). 4567 4568**System capability**: SystemCapability.Account.AppAccount 4569 4570| Name | Value | Description | 4571| ----------------------------------- | ----- | ------------ | 4572| SUCCESS | 0 | The operation is successful. | 4573| ERROR_ACCOUNT_NOT_EXIST | 10001 | The app account does not exist. | 4574| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The **AppAccountManager** service is abnormal. | 4575| ERROR_INVALID_PASSWORD | 10003 | The password is invalid. | 4576| ERROR_INVALID_REQUEST | 10004 | The request is invalid. | 4577| ERROR_INVALID_RESPONSE | 10005 | The response is invalid. | 4578| ERROR_NETWORK_EXCEPTION | 10006 | The network is abnormal. | 4579| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist. | 4580| ERROR_OAUTH_CANCELED | 10008 | The authentication is canceled. | 4581| ERROR_OAUTH_LIST_TOO_LARGE | 10009 | The size of the OAuth list exceeds the limit. | 4582| ERROR_OAUTH_SERVICE_BUSY | 10010 | The OAuth service is busy. | 4583| ERROR_OAUTH_SERVICE_EXCEPTION | 10011 | The OAuth service is abnormal. | 4584| ERROR_OAUTH_SESSION_NOT_EXIST | 10012 | The session to be authenticated does not exist. | 4585| ERROR_OAUTH_TIMEOUT | 10013 | The authentication timed out. | 4586| ERROR_OAUTH_TOKEN_NOT_EXIST | 10014 | The authorization token does not exist.| 4587| ERROR_OAUTH_TOKEN_TOO_MANY | 10015 | The number of OAuth tokens reaches the limit. | 4588| ERROR_OAUTH_UNSUPPORT_ACTION | 10016 | The authentication operation is not supported. | 4589| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE | 10017 | The authentication type is not supported. | 4590| ERROR_PERMISSION_DENIED | 10018 | The required permission is missing. | 4591 4592## AuthCallback<sup>9+</sup> 4593 4594Implements authenticator callbacks. 4595 4596### onResult<sup>9+</sup> 4597 4598onResult: (code: number, result?: AuthResult) => void 4599 4600Called to return the result of an authentication request. 4601 4602**System capability**: SystemCapability.Account.AppAccount 4603 4604**Parameters** 4605 4606| Name | Type | Mandatory | Description | 4607| ------ | -------------------- | ---- | ------ | 4608| code | number | Yes | Authentication result code.| 4609| result | [AuthResult](#authresult9) | No | Authentication result. | 4610 4611**Example** 4612 4613 ```js 4614 let appAccountManager = account_appAccount.createAppAccountManager(); 4615 var sessionId = "1234"; 4616 appAccountManager.getAuthCallback(sessionId).then((callback) => { 4617 var result = { 4618 accountInfo: { 4619 name: "Lisi", 4620 owner: "com.example.accountjsdemo", 4621 }, 4622 tokenInfo: { 4623 token: "xxxxxx", 4624 authType: "getSocialData" 4625 } 4626 }; 4627 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4628 }).catch((err) => { 4629 console.log("getAuthCallback err: " + JSON.stringify(err)); 4630 }); 4631 ``` 4632 4633### onRequestRedirected<sup>9+</sup> 4634 4635onRequestRedirected: (request: Want) => void 4636 4637Called to redirect a request. 4638 4639**System capability**: SystemCapability.Account.AppAccount 4640 4641**Parameters** 4642 4643| Name | Type | Mandatory | Description | 4644| ------- | ---- | ---- | ---------- | 4645| request | Want | Yes | Request to be redirected.| 4646 4647**Example** 4648 4649 ```js 4650 class MyAuthenticator extends account_appAccount.Authenticator { 4651 createAccountImplicitly(options, callback) { 4652 callback.onRequestRedirected({ 4653 bundleName: "com.example.accountjsdemo", 4654 abilityName: "com.example.accountjsdemo.LoginAbility", 4655 }); 4656 } 4657 4658 auth(name, authType, options, callback) { 4659 var result = { 4660 accountInfo: { 4661 name: "Lisi", 4662 owner: "com.example.accountjsdemo", 4663 }, 4664 tokenInfo: { 4665 token: "xxxxxx", 4666 authType: "getSocialData" 4667 } 4668 }; 4669 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4670 } 4671 } 4672 ``` 4673 4674### onRequestContinued<sup>9+</sup> 4675 4676onRequestContinued?: () => void 4677 4678Called to continue to process the request. 4679 4680**System capability**: SystemCapability.Account.AppAccount 4681 4682**Example** 4683 4684 ```js 4685 let appAccountManager = account_appAccount.createAppAccountManager(); 4686 var sessionId = "1234"; 4687 appAccountManager.getAuthCallback(sessionId).then((callback) => { 4688 callback.onRequestContinued(); 4689 }).catch((err) => { 4690 console.log("getAuthCallback err: " + JSON.stringify(err)); 4691 }); 4692 ``` 4693 4694## AuthenticatorCallback<sup>(deprecated)</sup> 4695 4696Provides OAuth authenticator callbacks. 4697 4698> **NOTE** 4699> 4700> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AuthCallback](#authcallback9). 4701 4702### onResult<sup>8+</sup> 4703 4704onResult: (code: number, result: {[key: string]: any}) => void 4705 4706Called to return the result of an authentication request. 4707 4708**System capability**: SystemCapability.Account.AppAccount 4709 4710**Parameters** 4711 4712| Name | Type | Mandatory | Description | 4713| ------ | -------------------- | ---- | ------ | 4714| code | number | Yes | Authentication result code.| 4715| result | {[key: string]: any} | Yes | Authentication result. | 4716 4717**Example** 4718 4719 ```js 4720 let appAccountManager = account_appAccount.createAppAccountManager(); 4721 var sessionId = "1234"; 4722 appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { 4723 var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi", 4724 [account_appAccount.Constants.KEY_OWNER]: "com.example.accountjsdemo", 4725 [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData", 4726 [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; 4727 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4728 }).catch((err) => { 4729 console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); 4730 }); 4731 ``` 4732 4733### onRequestRedirected<sup>8+</sup> 4734 4735onRequestRedirected: (request: Want) => void 4736 4737Called to redirect a request. 4738 4739**System capability**: SystemCapability.Account.AppAccount 4740 4741**Parameters** 4742 4743| Name | Type | Mandatory | Description | 4744| ------- | ---- | ---- | ---------- | 4745| request | Want | Yes | Request to be redirected.| 4746 4747**Example** 4748 4749 ```js 4750 class MyAuthenticator extends account_appAccount.Authenticator { 4751 addAccountImplicitly(authType, callerBundleName, options, callback) { 4752 callback.onRequestRedirected({ 4753 bundleName: "com.example.accountjsdemo", 4754 abilityName: "com.example.accountjsdemo.LoginAbility", 4755 }); 4756 } 4757 4758 authenticate(name, authType, callerBundleName, options, callback) { 4759 var result = {[account_appAccount.Constants.KEY_NAME]: name, 4760 [account_appAccount.Constants.KEY_AUTH_TYPE]: authType, 4761 [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; 4762 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4763 } 4764 } 4765 ``` 4766 4767### onRequestContinued<sup>9+</sup> 4768 4769onRequestContinued?: () => void 4770 4771Called to continue to process the request. 4772 4773**System capability**: SystemCapability.Account.AppAccount 4774 4775**Example** 4776 4777 ```js 4778 let appAccountManager = account_appAccount.createAppAccountManager(); 4779 var sessionId = "1234"; 4780 appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { 4781 callback.onRequestContinued(); 4782 }).catch((err) => { 4783 console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); 4784 }); 4785 ``` 4786 4787## Authenticator<sup>8+</sup> 4788 4789Provides APIs to operate the authenticator. 4790 4791### createAccountImplicitly<sup>9+</sup> 4792 4793createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void 4794 4795Creates an app account implicitly based on the specified account owner. This API uses an asynchronous callback to return the result. 4796 4797**System capability**: SystemCapability.Account.AppAccount 4798 4799**Parameters** 4800 4801| Name | Type | Mandatory | Description | 4802| ---------------- | --------------------- | ---- | --------------- | 4803| options | [CreateAccountImplicitlyOptions](#createaccountimplicitlyoptions9) | Yes | Options for implicitly creating an account. | 4804| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| 4805 4806### addAccountImplicitly<sup>(deprecated)</sup> 4807 4808addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void 4809 4810Adds an app account implicitly based on the specified authentication type and options. This API uses an asynchronous callback to return the result. 4811 4812> **NOTE** 4813> 4814> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [createAccountImplicitly](#createaccountimplicitly9-2). 4815 4816**System capability**: SystemCapability.Account.AppAccount 4817 4818**Parameters** 4819 4820| Name | Type | Mandatory | Description | 4821| ---------------- | --------------------- | ---- | --------------- | 4822| authType | string | Yes | Authentication type. | 4823| callerBundleName | string | Yes | Bundle name of the authentication requester. | 4824| options | {[key: string]: any} | Yes | Options for the authentication. | 4825| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the authentication result.| 4826 4827### auth<sup>9+</sup> 4828 4829auth(name: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void 4830 4831Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. 4832 4833**System capability**: SystemCapability.Account.AppAccount 4834 4835**Parameters** 4836 4837| Name | Type | Mandatory | Description | 4838| ---------------- | --------------------- | ---- | --------------- | 4839| name | string | Yes | Name of the target app account. | 4840| authType | string | Yes | Authentication type. | 4841| callerBundleName | string | Yes | Authentication type. | 4842| options | {[key: string]: Object} | Yes | Options for the authentication. | 4843| callback | [AuthCallback](#authcallback9) | Yes | Callback invoked to return the result.| 4844 4845### authenticate<sup>(deprecated)</sup> 4846 4847authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void 4848 4849Authenticates an app account to obtain the authorization token. This API uses an asynchronous callback to return the result. 4850 4851> **NOTE** 4852> 4853> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [auth](#auth9-2). 4854 4855**System capability**: SystemCapability.Account.AppAccount 4856 4857**Parameters** 4858 4859| Name | Type | Mandatory | Description | 4860| ---------------- | --------------------- | ---- | --------------- | 4861| name | string | Yes | Name of the target app account. | 4862| authType | string | Yes | Authentication type. | 4863| callerBundleName | string | Yes | Bundle name of the authentication requester. | 4864| options | {[key: string]: any} | Yes | Options for the authentication. | 4865| callback | [AuthenticatorCallback](#authenticatorcallbackdeprecated) | Yes | Authenticator callback invoked to return the authentication result.| 4866 4867### verifyCredential<sup>9+</sup> 4868 4869verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void; 4870 4871Verifies the credential of an app account. This API uses an asynchronous callback to return the result. 4872 4873**System capability**: SystemCapability.Account.AppAccount 4874 4875**Parameters** 4876 4877| Name | Type | Mandatory | Description | 4878| ---------------- | --------------------- | ---- | --------------- | 4879| name | string | Yes | Name of the target app account. | 4880| options | [VerifyCredentialOptions](#verifycredentialoptions9) | Yes | Options for credential verification. | 4881| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the verification result.| 4882 4883### setProperties<sup>9+</sup> 4884 4885setProperties(options: SetPropertiesOptions, callback: AuthCallback): void; 4886 4887Sets the authenticator properties. This API uses an asynchronous callback to return the result. 4888 4889**System capability**: SystemCapability.Account.AppAccount 4890 4891**Parameters** 4892 4893| Name | Type | Mandatory | Description | 4894| ---------------- | --------------------- | ---- | --------------- | 4895| options | [SetPropertiesOptions](#setpropertiesoptions9) | Yes | Authenticator properties to set. | 4896| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| 4897 4898### checkAccountLabels<sup>9+</sup> 4899 4900checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void; 4901 4902Checks the account labels. This API uses an asynchronous callback to return the result. 4903 4904**System capability**: SystemCapability.Account.AppAccount 4905 4906**Parameters** 4907 4908| Name | Type | Mandatory | Description | 4909| ---------------- | --------------------- | ---- | --------------- | 4910| name | string | Yes | Name of the target app account. | 4911| labels | Array<string> | Yes | Labels to check. | 4912| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the check result.| 4913 4914### checkAccountRemovable<sup>9+</sup> 4915 4916checkAccountRemovable(name: string, callback: AuthCallback): void; 4917 4918Checks whether an app account can be deleted. This API uses an asynchronous callback to return the result. 4919 4920**System capability**: SystemCapability.Account.AppAccount 4921 4922**Parameters** 4923 4924| Name | Type | Mandatory | Description | 4925| ---------------- | --------------------- | ---- | --------------- | 4926| name | string | Yes | Name of the target app account. | 4927| callback | [AuthCallback](#authcallback9) | Yes | Authenticator callback invoked to return the result.| 4928 4929### getRemoteObject<sup>9+</sup> 4930 4931getRemoteObject(): rpc.RemoteObject; 4932 4933Obtains the remote object of an authenticator. This API cannot be overloaded. 4934 4935**System capability**: SystemCapability.Account.AppAccount 4936 4937**Example** 4938 4939 ```js 4940 class MyAuthenticator extends account_appAccount.Authenticator { 4941 addAccountImplicitly(authType, callerBundleName, options, callback) { 4942 callback.onRequestRedirected({ 4943 bundleName: "com.example.accountjsdemo", 4944 abilityName: "com.example.accountjsdemo.LoginAbility", 4945 }); 4946 } 4947 4948 authenticate(name, authType, callerBundleName, options, callback) { 4949 var result = {[account_appAccount.Constants.KEY_NAME]: name, 4950 [account_appAccount.Constants.KEY_AUTH_TYPE]: authType, 4951 [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; 4952 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4953 } 4954 4955 verifyCredential(name, options, callback) { 4956 callback.onRequestRedirected({ 4957 bundleName: "com.example.accountjsdemo", 4958 abilityName: "com.example.accountjsdemo.VerifyAbility", 4959 parameters: { 4960 name: name 4961 } 4962 }); 4963 } 4964 4965 setProperties(options, callback) { 4966 callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); 4967 } 4968 4969 checkAccountLabels(name, labels, callback) { 4970 var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; 4971 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4972 } 4973 4974 checkAccountRemovable(name, callback) { 4975 var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true}; 4976 callback.onResult(account_appAccount.ResultCode.SUCCESS, result); 4977 } 4978 } 4979 var authenticator = null; 4980 export default { 4981 onConnect(want) { 4982 authenticator = new MyAuthenticator(); 4983 return authenticator.getRemoteObject(); 4984 } 4985 } 4986 ``` 4987