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