• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# App Account Management
2
3> **NOTE**<br>
4> 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.
5
6
7## Modules to Import
8
9```js
10import account_appAccount from '@ohos.account.appAccount';
11```
12
13
14## account_appAccount.createAppAccountManager
15
16createAppAccountManager(): AppAccountManager
17
18Creates an **AppAccountManager** instance.
19
20**System capability**: SystemCapability.Account.AppAccount
21
22**Return value**
23| Type               | Description          |
24| ----------------- | ------------ |
25| AppAccountManager | **AppAccountManager** instance created.|
26
27**Example**
28  ```js
29  const appAccountManager = account_appAccount.createAppAccountManager();
30  ```
31
32## AppAccountManager
33
34Provides methods to manage app accounts.
35
36### addAccount
37
38addAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
39
40Adds an app account to the **AppAccountManager** service. This API uses an asynchronous callback to return the result.
41
42**System capability**: SystemCapability.Account.AppAccount
43
44**Parameters**
45
46| Name     | Type                       | Mandatory  | Description                   |
47| -------- | ------------------------- | ---- | --------------------- |
48| name     | string                    | Yes   | Name of the app account to add.         |
49| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is added.|
50
51**Example**
52
53  ```js
54  const appAccountManager = account_appAccount.createAppAccountManager();
55  appAccountManager.addAccount("WangWu", (err) => {
56      console.log("addAccount err: " + JSON.stringify(err));
57  });
58  ```
59
60### addAccount
61
62addAccount(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
63
64Adds an app account and its additional information to the **AppAccountManager** service. This method uses an asynchronous callback to return the result.
65
66**System capability**: SystemCapability.Account.AppAccount
67
68**Parameters**
69
70| Name      | Type                       | Mandatory  | Description                                      |
71| --------- | ------------------------- | ---- | ---------------------------------------- |
72| name      | string                    | Yes   | Name of the app account to add.                            |
73| extraInfo | string                    | Yes   | Additional information (for example, token) of the app account to add. The additional information cannot contain sensitive information about the app account.|
74| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account and its additional information are added.           |
75
76**Example**
77
78  ```js
79  const appAccountManager = account_appAccount.createAppAccountManager();
80  appAccountManager.addAccount("LiSi", "token101", (err) => {
81      console.log("addAccount err: " + JSON.stringify(err));
82  });
83  ```
84
85
86
87### addAccount
88
89addAccount(name: string, extraInfo?: string): Promise&lt;void&gt;
90
91Adds an app account and its additional information to the **AppAccountManager** service. This method uses a promise to return the result.
92
93**System capability**: SystemCapability.Account.AppAccount
94
95**Parameters**
96
97| Name      | Type    | Mandatory  | Description                              |
98| --------- | ------ | ---- | -------------------------------- |
99| name      | string | Yes   | Name of the app account to add.                    |
100| extraInfo | string | Yes   | Additional information of the app account to add. The additional information cannot contain sensitive information about the app account.|
101
102**Return value**
103
104| Type                 | Description                   |
105| ------------------- | --------------------- |
106| Promise&lt;void&gt; | Promise used to return the result.|
107
108**Example**
109
110  ```js
111  const appAccountManager = account_appAccount.createAppAccountManager();
112  appAccountManager.addAccount("LiSi", "token101").then(()=> {
113      console.log('addAccount Success');
114  }).catch((err) => {
115      console.log("addAccount err: "  + JSON.stringify(err));
116  });
117  ```
118
119### addAccountImplicitly<sup>8+</sup>
120
121addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
122
123Implicitly adds an app account based on the specified account owner, authentication type, and options. This method uses an asynchronous callback to return the result.
124
125**System capability**: SystemCapability.Account.AppAccount
126
127**Parameters**
128
129| Name     | Type                   | Mandatory  | Description             |
130| -------- | --------------------- | ---- | --------------- |
131| owner    | string                | Yes   | Bundle name of the app account to add.|
132| authType | string                | Yes   | Authentication type of the app account to add. |
133| options  | {[key: string]: any}  | Yes   | Options for the authentication.     |
134| callback | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
135
136**Example**
137
138  ```js
139  import featureAbility from '@ohos.ability.featureAbility';
140
141  function onResultCallback(code, result) {
142      console.log("resultCode: "  + code);
143      console.log("result: "  + JSON.stringify(result));
144  }
145
146  function onRequestRedirectedCallback(request) {
147      let abilityStartSetting = {want: request};
148      featureAbility.startAbility(abilityStartSetting, (err)=>{
149          console.log("startAbility err: " + JSON.stringify(err));
150      });
151  }
152
153  const appAccountManager = account_appAccount.createAppAccountManager();
154  appAccountManager.addAccountImplicitly("com.example.ohos.accountjsdemo", "getSocialData", {}, {
155      onResult: onResultCallback,
156      onRequestRedirected: onRequestRedirectedCallback
157  });
158  ```
159
160### deleteAccount
161
162deleteAccount(name: string, callback: AsyncCallback&lt;void&gt;): void
163
164Deletes an app account from the **AppAccountManager** service. This API uses an asynchronous callback to return the result.
165
166**System capability**: SystemCapability.Account.AppAccount
167
168**Parameters**
169
170| Name     | Type                       | Mandatory  | Description               |
171| -------- | ------------------------- | ---- | ----------------- |
172| name     | string                    | Yes   | Name of the app account to delete.     |
173| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is deleted.|
174
175**Example**
176
177  ```js
178  const appAccountManager = account_appAccount.createAppAccountManager();
179  appAccountManager.deleteAccount("ZhaoLiu", (err) => {
180      console.log("deleteAccount err: " + JSON.stringify(err));
181   });
182  ```
183
184### deleteAccount
185
186deleteAccount(name: string): Promise&lt;void&gt;
187
188Deletes an app account from the **AppAccountManager** service. This API uses a promise to return the result.
189
190**System capability**: SystemCapability.Account.AppAccount
191
192**Parameters**
193
194| Name | Type    | Mandatory  | Description          |
195| ---- | ------ | ---- | ------------ |
196| name | string | Yes   | Name of the app account to delete.|
197
198**Return value**
199
200| Type                 | Description                   |
201| :------------------ | :-------------------- |
202| Promise&lt;void&gt; | Promise used to return the result.|
203
204**Example**
205
206  ```js
207  const appAccountManager = account_appAccount.createAppAccountManager();
208  appAccountManager.deleteAccount("ZhaoLiu").then(() => {
209        console.log('deleteAccount Success');
210   }).catch((err) => {
211      console.log("deleteAccount err: "  + JSON.stringify(err));
212  });
213  ```
214
215### disableAppAccess
216
217disableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
218
219Disables an app account from accessing an application with the given bundle name. This method uses an asynchronous callback to return the result.
220
221**System capability**: SystemCapability.Account.AppAccount
222
223**Parameters**
224
225| Name       | Type                       | Mandatory  | Description                             |
226| ---------- | ------------------------- | ---- | ------------------------------- |
227| name       | string                    | Yes   | Name of the target app account.              |
228| bundleName | string                    | Yes   | Bundle name of the app.                      |
229| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is disabled from accessing the application with the given bundle name.|
230
231**Example**
232
233  ```js
234  const appAccountManager = account_appAccount.createAppAccountManager();
235  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => {
236      console.log("disableAppAccess err: " + JSON.stringify(err));
237  });
238  ```
239
240### disableAppAccess
241
242disableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
243
244Disables an app account from accessing an application with the given bundle name. This method uses a promise to return the result.
245
246**System capability**: SystemCapability.Account.AppAccount
247
248**Parameters**
249
250| Name       | Type    | Mandatory  | Description               |
251| ---------- | ------ | ---- | ----------------- |
252| name       | string | Yes   | Name of the target app account.|
253| bundleName | string | Yes   | Bundle name of the app.        |
254
255**Return value**
256
257| Type                 | Description                   |
258| :------------------ | :-------------------- |
259| Promise&lt;void&gt; | Promise used to return the result.|
260
261**Example**
262
263  ```js
264  const appAccountManager = account_appAccount.createAppAccountManager();
265  appAccountManager.disableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => {
266      console.log('disableAppAccess Success');
267  }).catch((err) => {
268      console.log("disableAppAccess err: "  + JSON.stringify(err));
269  });
270  ```
271
272### enableAppAccess
273
274enableAppAccess(name: string, bundleName: string, callback: AsyncCallback&lt;void&gt;): void
275
276Enables an app account to access an application with the given bundle name. This method uses an asynchronous callback to return the result.
277
278**System capability**: SystemCapability.Account.AppAccount
279
280**Parameters**
281
282| Name       | Type                       | Mandatory  | Description                             |
283| ---------- | ------------------------- | ---- | ------------------------------- |
284| name       | string                    | Yes   | Name of the target app account.                        |
285| bundleName | string                    | Yes   | Bundle name of the app.                      |
286| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the app account is enabled to access the application with the given bundle name.|
287
288**Example**
289
290  ```js
291  const appAccountManager = account_appAccount.createAppAccountManager();
292  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo", (err) => {
293      console.log("enableAppAccess: " + JSON.stringify(err));
294   });
295  ```
296
297### enableAppAccess
298
299enableAppAccess(name: string, bundleName: string): Promise&lt;void&gt;
300
301Enables an app account to access an application with the given bundle name. This method uses a promise to return the result.
302
303**System capability**: SystemCapability.Account.AppAccount
304
305**Parameters**
306
307| Name       | Type    | Mandatory  | Description       |
308| ---------- | ------ | ---- | --------- |
309| name       | string | Yes   | Name of the target app account.  |
310| bundleName | string | Yes   | Bundle name of the app.|
311
312**Return value**
313
314| Type                 | Description                   |
315| :------------------ | :-------------------- |
316| Promise&lt;void&gt; | Promise used to return the result.|
317
318**Example**
319
320  ```js
321  const appAccountManager = account_appAccount.createAppAccountManager();
322  appAccountManager.enableAppAccess("ZhangSan", "com.example.ohos.accountjsdemo").then(() => {
323       console.log('enableAppAccess Success');
324  }).catch((err) => {
325      console.log("enableAppAccess err: "  + JSON.stringify(err));
326  });
327  ```
328
329### checkAppAccountSyncEnable
330
331checkAppAccountSyncEnable(name: string, callback: AsyncCallback&lt;boolean&gt;): void
332
333Checks whether an app account allows app data synchronization. This API uses an asynchronous callback to return the result.
334
335**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
336
337**System capability**: SystemCapability.Account.AppAccount
338
339**Parameters**
340
341| Name     | Type                          | Mandatory  | Description                    |
342| -------- | ---------------------------- | ---- | ---------------------- |
343| name     | string                       | Yes   | Name of the target app account.               |
344| callback | AsyncCallback&lt;boolean&gt; | Yes   | Callback used to return whether the app account allows application data synchronization.|
345
346**Example**
347
348  ```js
349  const appAccountManager = account_appAccount.createAppAccountManager();
350  appAccountManager.checkAppAccountSyncEnable("ZhangSan", (err, result) => {
351      console.log("checkAppAccountSyncEnable err: " + JSON.stringify(err));
352      console.log('checkAppAccountSyncEnable result: ' + result);
353  });
354  ```
355
356### checkAppAccountSyncEnable
357
358checkAppAccountSyncEnable(name: string): Promise&lt;boolean&gt;
359
360Checks whether an app account allows app data synchronization. This API uses a promise to return the result.
361
362**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
363
364**System capability**: SystemCapability.Account.AppAccount
365
366**Parameters**
367
368| Name | Type    | Mandatory  | Description     |
369| ---- | ------ | ---- | ------- |
370| name | string | Yes   | Name of the target app account.|
371
372**Return value**
373
374| Type                    | Description                   |
375| :--------------------- | :-------------------- |
376| Promise&lt;boolean&gt; | Promise used to return the result.|
377
378**Example**
379
380  ```js
381  const appAccountManager = account_appAccount.createAppAccountManager();
382  appAccountManager.checkAppAccountSyncEnable("ZhangSan").then((data) => {
383      console.log('checkAppAccountSyncEnable, result: ' + data);
384  }).catch((err) => {
385      console.log("checkAppAccountSyncEnable err: "  + JSON.stringify(err));
386  });
387  ```
388
389### setAccountCredential
390
391setAccountCredential(name: string, credentialType: string, credential: string,callback: AsyncCallback&lt;void&gt;): void
392
393Sets a credential for an app account. This API uses an asynchronous callback to return the result.
394
395**System capability**: SystemCapability.Account.AppAccount
396
397**Parameters**
398
399| Name           | Type                       | Mandatory  | Description            |
400| -------------- | ------------------------- | ---- | -------------- |
401| name           | string                    | Yes   | Name of the target app account.    |
402| credentialType | string                    | Yes   | Type of the credential to set.    |
403| credential     | string                    | Yes   | Credential to set.       |
404| callback       | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when a credential is set for the specified app account.|
405
406**Example**
407
408  ```js
409  const appAccountManager = account_appAccount.createAppAccountManager();
410  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001", (err) => {
411      console.log("setAccountCredential err: " + JSON.stringify(err));
412  });
413  ```
414
415### setAccountCredential
416
417setAccountCredential(name: string, credentialType: string, credential: string): Promise&lt;void&gt;
418
419Sets a credential for an app account. This API uses a promise to return the result.
420
421**System capability**: SystemCapability.Account.AppAccount
422
423**Parameters**
424
425| Name           | Type    | Mandatory  | Description        |
426| -------------- | ------ | ---- | ---------- |
427| name           | string | Yes   | Name of the target app account.  |
428| credentialType | string | Yes   | Type of the credential to set.|
429| credential     | string | Yes   | Credential to set.   |
430
431**Return value**
432
433| Type                 | Description                   |
434| :------------------ | :-------------------- |
435| Promise&lt;void&gt; | Promise used to return the result.|
436
437**Example**
438
439  ```js
440  const appAccountManager = account_appAccount.createAppAccountManager();
441  appAccountManager.setAccountCredential("ZhangSan", "credentialType001", "credential001").then(() => {
442      console.log('setAccountCredential Success');
443  }).catch((err) => {
444      console.log("setAccountCredential err: "  + JSON.stringify(err));
445  });
446  ```
447
448### setAccountExtraInfo
449
450setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback&lt;void&gt;): void
451
452Sets additional information for an app account. This API uses an asynchronous callback to return the result.
453
454**System capability**: SystemCapability.Account.AppAccount
455
456**Parameters**
457
458| Name      | Type                       | Mandatory  | Description              |
459| --------- | ------------------------- | ---- | ---------------- |
460| name      | string                    | Yes   | Name of the target app account.        |
461| extraInfo | string                    | Yes   | Additional information to set.       |
462| callback  | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when additional information is set for the specified app account.|
463
464**Example**
465
466  ```js
467  const appAccountManager = account_appAccount.createAppAccountManager();
468  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002", (err) => {
469      console.log("setAccountExtraInfo err: " + JSON.stringify(err));
470  });
471  ```
472
473### setAccountExtraInfo
474
475setAccountExtraInfo(name: string, extraInfo: string): Promise&lt;void&gt;
476
477Sets additional information for an app account. This API uses a promise to return the result.
478
479**System capability**: SystemCapability.Account.AppAccount
480
481**Parameters**
482
483| Name      | Type    | Mandatory  | Description       |
484| --------- | ------ | ---- | --------- |
485| name      | string | Yes   | Name of the target app account. |
486| extraInfo | string | Yes   | Additional information to set.|
487
488**Return value**
489
490| Type                 | Description                   |
491| :------------------ | :-------------------- |
492| Promise&lt;void&gt; | Promise used to return the result.|
493
494**Example**
495
496  ```js
497  const appAccountManager = account_appAccount.createAppAccountManager();
498  appAccountManager.setAccountExtraInfo("ZhangSan", "Tk002").then(() => {
499      console.log('setAccountExtraInfo Success');
500  }).catch((err) => {
501      console.log("setAccountExtraInfo err: "  + JSON.stringify(err));
502  });
503  ```
504
505### setAppAccountSyncEnable
506
507setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
508
509Sets whether to enable app data synchronization for an app account. This API uses an asynchronous callback to return the result.
510
511**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
512
513**System capability**: SystemCapability.Account.AppAccount
514
515**Parameters**
516
517| Name     | Type                       | Mandatory  | Description                       |
518| -------- | ------------------------- | ---- | ------------------------- |
519| name     | string                    | Yes   | Name of the target app account.                 |
520| isEnable | boolean                   | Yes   | Whether to enable app data synchronization.              |
521| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when app data synchronization is enabled or disabled for the app account.|
522
523**Example**
524
525  ```js
526  const appAccountManager = account_appAccount.createAppAccountManager();
527  appAccountManager.setAppAccountSyncEnable("ZhangSan", true, (err) => {
528      console.log("setAppAccountSyncEnable err: " + JSON.stringify(err));
529  });
530  ```
531
532### setAppAccountSyncEnable
533
534setAppAccountSyncEnable(name: string, isEnable: boolean): Promise&lt;void&gt;
535
536Sets whether to enable app data synchronization for an app account. This API uses a promise to return the result.
537
538**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
539
540**System capability**: SystemCapability.Account.AppAccount
541
542**Parameters**
543
544| Name     | Type     | Mandatory  | Description         |
545| -------- | ------- | ---- | ----------- |
546| name     | string  | Yes   | Name of the target app account.   |
547| isEnable | boolean | Yes   | Whether to enable app data synchronization.|
548
549**Return value**
550
551| Type                 | Description                   |
552| :------------------ | :-------------------- |
553| Promise&lt;void&gt; | Promise used to return the result.|
554
555**Example**
556
557  ```js
558  const appAccountManager = account_appAccount.createAppAccountManager();
559  appAccountManager .setAppAccountSyncEnable("ZhangSan", true).then(() => {
560      console.log('setAppAccountSyncEnable Success');
561  }).catch((err) => {
562      console.log("setAppAccountSyncEnable err: "  + JSON.stringify(err));
563  });
564  ```
565
566### setAssociatedData
567
568setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
569
570Sets data to be associated with an app account. This API uses an asynchronous callback to return the result.
571
572**System capability**: SystemCapability.Account.AppAccount
573
574**Parameters**
575
576| Name     | Type                       | Mandatory  | Description               |
577| -------- | ------------------------- | ---- | ----------------- |
578| name     | string                    | Yes   | Name of the target app account.         |
579| key      | string                    | Yes   | Key of the data to set. The private key can be customized.|
580| value    | string                    | Yes   | Value of the data to be set.        |
581| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked when the data associated with the specified app account is set.|
582
583**Example**
584
585  ```js
586  const appAccountManager = account_appAccount.createAppAccountManager();
587  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001", (err) => {
588      console.log("setAssociatedData err: " + JSON.stringify(err));
589  });
590  ```
591
592### setAssociatedData
593
594setAssociatedData(name: string, key: string, value: string): Promise&lt;void&gt;
595
596Sets data to be associated with an app account. This API uses a promise to return the result.
597
598**System capability**: SystemCapability.Account.AppAccount
599
600**Parameters**
601
602| Name  | Type    | Mandatory  | Description               |
603| ----- | ------ | ---- | ----------------- |
604| name  | string | Yes   | Name of the target app account.         |
605| key   | string | Yes   | Key of the data to set. The private key can be customized.|
606| value | string | Yes   | Value of the data to be set.        |
607
608**Return value**
609
610| Type                 | Description                   |
611| :------------------ | :-------------------- |
612| Promise&lt;void&gt; | Promise used to return the result.|
613
614**Example**
615
616  ```js
617  const appAccountManager = account_appAccount.createAppAccountManager();
618  appAccountManager.setAssociatedData("ZhangSan", "k001", "v001").then(() => {
619      console.log('setAssociatedData Success');
620  }).catch((err) => {
621      console.log("setAssociatedData err: "  + JSON.stringify(err));
622  });
623  ```
624
625### getAccountCredential
626
627getAccountCredential(name: string, credentialType: string, callback: AsyncCallback&lt;string&gt;): void
628
629Obtains the credential of an app account. This method uses an asynchronous callback to return the result.
630
631**System capability**: SystemCapability.Account.AppAccount
632
633**Parameters**
634
635| Name           | Type                         | Mandatory  | Description            |
636| -------------- | --------------------------- | ---- | -------------- |
637| name           | string                      | Yes   | Name of the target app account.       |
638| credentialType | string                      | Yes   | Type of the credential to obtain.    |
639| callback       | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the credential obtained.|
640
641**Example**
642
643  ```js
644  const appAccountManager = account_appAccount.createAppAccountManager();
645  appAccountManager.getAccountCredential("ZhangSan", "credentialType001", (err, result) => {
646      console.log("getAccountCredential err: " + JSON.stringify(err));
647      console.log('getAccountCredential result: ' + result);
648  });
649  ```
650
651### getAccountCredential
652
653getAccountCredential(name: string, credentialType: string): Promise&lt;string&gt;
654
655Obtains the credential of an app account. This API uses a promise to return the result.
656
657**System capability**: SystemCapability.Account.AppAccount
658
659**Parameters**
660
661| Name           | Type    | Mandatory  | Description        |
662| -------------- | ------ | ---- | ---------- |
663| name           | string | Yes   | Name of the target app account.   |
664| credentialType | string | Yes   | Type of the credential to obtain.|
665
666**Return value**
667
668| Type                   | Description                   |
669| :-------------------- | :-------------------- |
670| Promise&lt;string&gt; | Promise used to return the result.|
671
672**Example**
673
674  ```js
675  const appAccountManager = account_appAccount.createAppAccountManager();
676  appAccountManager.getAccountCredential("ZhangSan", "credentialType001").then((data) => {
677      console.log('getAccountCredential, result: ' + data);
678  }).catch((err) => {
679      console.log("getAccountCredential err: "  + JSON.stringify(err));
680  });
681  ```
682
683### getAccountExtraInfo
684
685getAccountExtraInfo(name: string, callback: AsyncCallback&lt;string&gt;): void
686
687Obtains additional information of an app account. This method uses an asynchronous callback to return the result.
688
689**System capability**: SystemCapability.Account.AppAccount
690
691**Parameters**
692
693| Name     | Type                         | Mandatory  | Description              |
694| -------- | --------------------------- | ---- | ---------------- |
695| name     | string                      | Yes   | Name of the target app account.         |
696| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the additional information of the specified app account.|
697
698**Example**
699
700  ```js
701  const appAccountManager = account_appAccount.createAppAccountManager();
702  appAccountManager.getAccountExtraInfo("ZhangSan", (err, result) => {
703      console.log("getAccountExtraInfo err: " + JSON.stringify(err));
704      console.log('getAccountExtraInfo result: ' + result);
705  });
706  ```
707
708### getAccountExtraInfo
709
710getAccountExtraInfo(name: string): Promise&lt;string&gt;
711
712Obtains additional information of an app account. This API uses a promise to return the result.
713
714**System capability**: SystemCapability.Account.AppAccount
715
716**Parameters**
717
718| Name | Type    | Mandatory  | Description     |
719| ---- | ------ | ---- | ------- |
720| name | string | Yes   | Name of the target app account.|
721
722**Return value**
723
724| Type                   | Description                   |
725| :-------------------- | :-------------------- |
726| Promise&lt;string&gt; | Promise used to return the result.|
727
728**Example**
729
730  ```js
731  const appAccountManager = account_appAccount.createAppAccountManager();
732  appAccountManager.getAccountExtraInfo("ZhangSan").then((data) => {
733      console.log('getAccountExtraInfo, result: ' + data);
734  }).catch((err) => {
735      console.log("getAccountExtraInfo err: "  + JSON.stringify(err));
736  });
737  ```
738
739### getAssociatedData
740
741getAssociatedData(name: string, key: string, callback: AsyncCallback&lt;string&gt;): void
742
743Obtains data associated with an app account. This API uses an asynchronous callback to return the result.
744
745**System capability**: SystemCapability.Account.AppAccount
746
747**Parameters**
748
749| Name     | Type                         | Mandatory  | Description               |
750| -------- | --------------------------- | ---- | ----------------- |
751| name     | string                      | Yes   | Name of the target app account.          |
752| key      | string                      | Yes   | Key of the data to obtain.      |
753| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the data associated with the specified app account.|
754
755**Example**
756
757  ```js
758  const appAccountManager = account_appAccount.createAppAccountManager();
759  appAccountManager.getAssociatedData("ZhangSan", "k001", (err, result) => {
760      console.log("getAssociatedData err: " + JSON.stringify(err));
761      console.log('getAssociatedData result: ' + result);
762  });
763  ```
764
765### getAssociatedData
766
767getAssociatedData(name: string, key: string): Promise&lt;string&gt;
768
769Obtains data associated with an app account. This API uses a promise to return the result.
770
771**System capability**: SystemCapability.Account.AppAccount
772
773**Parameters**
774
775| Name | Type    | Mandatory  | Description         |
776| ---- | ------ | ---- | ----------- |
777| name | string | Yes   | Name of the target app account.    |
778| key  | string | Yes   | Key of the data to obtain.|
779
780**Return value**
781
782| Type                   | Description                   |
783| :-------------------- | :-------------------- |
784| Promise&lt;string&gt; | Promise used to return the result.|
785
786**Example**
787
788  ```js
789  const appAccountManager = account_appAccount.createAppAccountManager();
790  appAccountManager.getAssociatedData("ZhangSan", "k001").then((data) => {
791       console.log('getAssociatedData: ' + data);
792  }).catch((err) => {
793      console.log("getAssociatedData err: "  + JSON.stringify(err));
794  });
795  ```
796
797### getAllAccessibleAccounts
798
799getAllAccessibleAccounts(callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
800
801Obtains information about all accessible app accounts. This API uses an asynchronous callback to return the result.
802
803**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
804
805**System capability**: SystemCapability.Account.AppAccount
806
807**Parameters**
808
809| Name     | Type                                      | Mandatory  | Description      |
810| -------- | ---------------------------------------- | ---- | -------- |
811| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
812
813**Example**
814
815  ```js
816  const appAccountManager = account_appAccount.createAppAccountManager();
817  appAccountManager.getAllAccessibleAccounts((err, data)=>{
818  	console.debug("getAllAccessibleAccounts err:" + JSON.stringify(err));
819  	console.debug("getAllAccessibleAccounts data:" + JSON.stringify(data));
820  });
821  ```
822
823### getAllAccessibleAccounts
824
825getAllAccessibleAccounts(): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
826
827Obtains information about all accessible app accounts. This API uses a promise to return the result.
828
829**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
830
831**System capability**: SystemCapability.Account.AppAccount
832
833**Parameters**
834
835| Type                                      | Description                   |
836| ---------------------------------------- | --------------------- |
837| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise used to return the result.|
838
839**Example**
840
841  ```js
842  const appAccountManager = account_appAccount.createAppAccountManager();
843  appAccountManager.getAllAccessibleAccounts().then((data) => {
844       console.log('getAllAccessibleAccounts: ' + data);
845  }).catch((err) => {
846      console.log("getAllAccessibleAccounts err: "  + JSON.stringify(err));
847  });
848  ```
849
850### getAllAccounts
851
852getAllAccounts(owner: string, callback: AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
853
854Obtains information about all app accounts of the specified app. This API uses an asynchronous callback to return the result.
855
856**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
857
858**System capability**: SystemCapability.Account.AppAccount
859
860**Parameters**
861
862| Name     | Type                                      | Mandatory  | Description      |
863| -------- | ---------------------------------------- | ---- | -------- |
864| owner    | string                                   | Yes   | Bundle name of the app.   |
865| callback | AsyncCallback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return information about all accessible app accounts.|
866
867**Example**
868
869  ```js
870  const appAccountManager = account.createAppAccountManager();
871  const selfBundle = "com.example.actsgetallaaccounts";
872  appAccountManager.getAllAccounts(selfBundle, (err, data)=>{
873  	console.debug("getAllAccounts err:" + JSON.stringify(err));
874  	console.debug("getAllAccounts data:" + JSON.stringify(data));
875  });
876  ```
877
878### getAllAccounts
879
880getAllAccounts(owner: string): Promise&lt;Array&lt;AppAccountInfo&gt;&gt;
881
882Obtains information about all app accounts of the specified app. This API uses a promise to return the result.
883
884**Required permissions**: ohos.permission.GET_ALL_APP_ACCOUNTS (available only to system applications)
885
886**System capability**: SystemCapability.Account.AppAccount
887
888**Parameters**
889
890| Name  | Type    | Mandatory  | Description   |
891| ----- | ------ | ---- | ----- |
892| owner | string | Yes   | Bundle name of the app.|
893
894**Parameters**
895
896| Type                                      | Description                   |
897| ---------------------------------------- | --------------------- |
898| Promise&lt;Array&lt;AppAccountInfo&gt;&gt; | Promise used to return the result.|
899
900**Example**
901
902  ```js
903  const appAccountManager = account_appAccount.createAppAccountManager();
904  const selfBundle = "com.example.actsgetallaaccounts";
905  appAccountManager.getAllAccounts(selfBundle).then((data) => {
906       console.log('getAllAccounts: ' + data);
907  }).catch((err) => {
908      console.log("getAllAccounts err: "  + JSON.stringify(err));
909  });
910  ```
911
912### on('change')
913
914on(type: 'change', owners: Array&lt;string&gt;, callback: Callback&lt;Array&lt;AppAccountInfo&gt;&gt;): void
915
916Subscribes to account changes of the specified account owners. This API uses an asynchronous callback to return the result.
917
918**System capability**: SystemCapability.Account.AppAccount
919
920**Parameters**
921
922| Name     | Type                                      | Mandatory  | Description                            |
923| -------- | ---------------------------------------- | ---- | ------------------------------ |
924| type     | 'change'                                 | Yes   | Type of the event to subscribe to. The subscriber will receive a notification when the account owners update their accounts.|
925| owners   | Array&lt;string&gt;                      | Yes   | Owners of the accounts.                     |
926| callback | Callback&lt;Array&lt;AppAccountInfo&gt;&gt; | Yes   | Callback invoked to return the account change.          |
927
928**Example**
929
930  ```js
931  const appAccountManager = account.createAppAccountManager();
932  function changeOnCallback(data){
933  	console.debug("receive change data:" + JSON.stringify(data));
934  }
935  try{
936  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
937  }
938  catch(err){
939  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
940  }
941  ```
942
943### off('change')
944
945off(type: 'change', callback?: Callback<Array\<AppAccountInfo>>): void
946
947Unsubscribes from account changes. This API uses an asynchronous callback to return the result.
948
949**System capability**: SystemCapability.Account.AppAccount
950
951**Parameters**
952
953| Name     | Type                              | Mandatory  | Description          |
954| -------- | -------------------------------- | ---- | ------------ |
955| type     | 'change'                         | Yes   | Account change event to unsubscribe from.   |
956| callback | Callback<Array\<AppAccountInfo>> | No   | Callback used to report the account change.|
957
958**Example**
959
960  ```js
961  const appAccountManager = account.createAppAccountManager();
962  function changeOnCallback(data){
963  	console.debug("receive change data:" + JSON.stringify(data));
964  	appAccountManager.off('change', function(){
965  		console.debug("off finish");
966  	})
967  }
968  try{
969  	appAccountManager.on('change', ["com.example.actsaccounttest"], changeOnCallback);
970  }
971  catch(err){
972  	console.error("on accountOnOffDemo err:" + JSON.stringify(err));
973  }
974  ```
975
976### authenticate<sup>8+</sup>
977
978authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
979
980Authenticates an app account to obtain the Open Authorization (OAuth) access token. This method uses an asynchronous callback to return the result.
981
982**System capability**: SystemCapability.Account.AppAccount
983
984**Parameters**
985
986| Name     | Type                   | Mandatory  | Description             |
987| -------- | --------------------- | ---- | --------------- |
988| name     | string                | Yes   | Name of the app account to authenticate.   |
989| owner    | string                | Yes   | Bundle name of the app.|
990| authType | string                | Yes   | Authentication type.          |
991| options  | {[key: string]: any}  | Yes   | Options for the authentication.      |
992| callback | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
993
994**Example**
995
996  ```js
997  import featureAbility from '@ohos.ability.featureAbility';
998
999  function onResultCallback(code, result) {
1000      console.log("resultCode: "  + code);
1001      console.log("result: "  + JSON.stringify(result));
1002  }
1003
1004  function onRequestRedirectedCallback(request) {
1005      let abilityStartSetting = {want: request};
1006      featureAbility.startAbility(abilityStartSetting, (err)=>{
1007          console.log("startAbility err: " + JSON.stringify(err));
1008      });
1009  }
1010
1011  const appAccountManager = account_appAccount.createAppAccountManager();
1012  appAccountManager.authenticate("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", {}, {
1013    onResult: onResultCallback,
1014    onRequestRedirected: onRequestRedirectedCallback
1015  });
1016  ```
1017
1018### getOAuthToken<sup>8+</sup>
1019
1020getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback&lt;string&gt;): void
1021
1022Obtains the OAuth token of an app account based on the specified authentication type. This method uses an asynchronous callback to return the result.
1023
1024**System capability**: SystemCapability.Account.AppAccount
1025
1026**Parameters**
1027
1028| Name     | Type                         | Mandatory  | Description         |
1029| -------- | --------------------------- | ---- | ----------- |
1030| name     | string                      | Yes   | Name of the target app account.   |
1031| owner    | string                      | Yes   | Bundle name of the app.|
1032| authType | string                      | Yes   | Authentication type.      |
1033| callback | AsyncCallback&lt;string&gt; | Yes   | Callback invoked to return the result.   |
1034
1035**Example**
1036
1037  ```js
1038  const appAccountManager = account_appAccount.createAppAccountManager();
1039  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", (err, data) => {
1040       console.log('getOAuthToken err: ' + JSON.stringify(err));
1041       console.log('getOAuthToken token: ' + data);
1042  });
1043  ```
1044
1045### getOAuthToken<sup>8+</sup>
1046
1047getOAuthToken(name: string, owner: string, authType: string): Promise&lt;string&gt;
1048
1049Obtains the OAuth token of an app account based on the specified authentication type. This API uses a promise to return the result.
1050
1051**System capability**: SystemCapability.Account.AppAccount
1052
1053**Parameters**
1054
1055| Name     | Type    | Mandatory  | Description         |
1056| -------- | ------ | ---- | ----------- |
1057| name     | string | Yes   | Name of the target app account.   |
1058| owner    | string | Yes   | Bundle name of the app.|
1059| authType | string | Yes   | Authentication type.      |
1060
1061**Parameters**
1062
1063| Type                   | Description                   |
1064| --------------------- | --------------------- |
1065| Promise&lt;string&gt; | Promise used to return the result.|
1066
1067**Example**
1068
1069  ```js
1070  const appAccountManager = account_appAccount.createAppAccountManager();
1071  appAccountManager.getOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData").then((data) => {
1072       console.log('getOAuthToken token: ' + data);
1073  }).catch((err) => {
1074      console.log("getOAuthToken err: "  + JSON.stringify(err));
1075  });
1076  ```
1077
1078### setOAuthToken<sup>8+</sup>
1079
1080setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
1081
1082Sets an OAuth token for an app account. This method uses an asynchronous callback to return the result.
1083
1084**System capability**: SystemCapability.Account.AppAccount
1085
1086**Parameters**
1087
1088| Name     | Type                       | Mandatory  | Description      |
1089| -------- | ------------------------- | ---- | -------- |
1090| name     | string                    | Yes   | Name of the target app account.|
1091| authType | string                    | Yes   | Authentication type.   |
1092| token    | string                    | Yes   | OAuth token to set.|
1093| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.|
1094
1095**Example**
1096
1097  ```js
1098  const appAccountManager = account_appAccount.createAppAccountManager();
1099  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx", (err) => {
1100      console.log('setOAuthToken err: ' + JSON.stringify(err));
1101  });
1102  ```
1103
1104### setOAuthToken<sup>8+</sup>
1105
1106setOAuthToken(name: string, authType: string, token: string): Promise&lt;void&gt;
1107
1108Sets an OAuth token for an app account. This API uses a promise to return the result.
1109
1110**System capability**: SystemCapability.Account.AppAccount
1111
1112**Parameters**
1113
1114| Name     | Type    | Mandatory  | Description      |
1115| -------- | ------ | ---- | -------- |
1116| name     | string | Yes   | Name of the target app account.|
1117| authType | string | Yes   | Authentication type.   |
1118| token    | string | Yes   | OAuth token to set.|
1119
1120**Parameters**
1121
1122| Type                 | Description                   |
1123| ------------------- | --------------------- |
1124| Promise&lt;void&gt; | Promise used to return the result.|
1125
1126**Example**
1127
1128  ```js
1129  const appAccountManager = account_appAccount.createAppAccountManager();
1130  appAccountManager.setOAuthToken("LiSi", "getSocialData", "xxxx").then(() => {
1131      console.log('setOAuthToken successfully');
1132  }).catch((err) => {
1133      console.log('setOAuthToken err: ' + JSON.stringify(err));
1134  });
1135  ```
1136
1137### deleteOAuthToken<sup>8+</sup>
1138
1139deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback&lt;void&gt;): void
1140
1141Deletes the specified OAuth token for an app account. This API uses an asynchronous callback to return the result.
1142
1143**System capability**: SystemCapability.Account.AppAccount
1144
1145**Parameters**
1146
1147| Name     | Type                       | Mandatory  | Description          |
1148| -------- | ------------------------- | ---- | ------------ |
1149| name     | string                    | Yes   | Name of the target app account.    |
1150| owner    | string                    | Yes   | Bundle name of the app. |
1151| authType | string                    | Yes   | Authentication type.       |
1152| token    | string                    | Yes   | OAuth token to delete.|
1153| callback | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.    |
1154
1155**Example**
1156
1157  ```js
1158  const appAccountManager = account_appAccount.createAppAccountManager();
1159  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx", (err) => {
1160       console.log('deleteOAuthToken err: ' + JSON.stringify(err));
1161  });
1162  ```
1163
1164### deleteOAuthToken<sup>8+</sup>
1165
1166deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise&lt;void&gt;
1167
1168Deletes the specified OAuth token for an app account. This API uses a promise to return the result.
1169
1170**System capability**: SystemCapability.Account.AppAccount
1171
1172**Parameters**
1173
1174| Name     | Type    | Mandatory  | Description          |
1175| -------- | ------ | ---- | ------------ |
1176| name     | string | Yes   | Name of the target app account.    |
1177| owner    | string | Yes   | Bundle name of the app. |
1178| authType | string | Yes   | Authentication type.       |
1179| token    | string | Yes   | OAuth token to delete.|
1180
1181**Parameters**
1182
1183| Type                 | Description                   |
1184| ------------------- | --------------------- |
1185| Promise&lt;void&gt; | Promise used to return the result.|
1186
1187**Example**
1188
1189  ```js
1190  const appAccountManager = account_appAccount.createAppAccountManager();
1191  appAccountManager.deleteOAuthToken("LiSi", "com.example.ohos.accountjsdemo", "getSocialData", "xxxxx").then(() => {
1192       console.log('deleteOAuthToken successfully');
1193  }).catch((err) => {
1194      console.log("deleteOAuthToken err: "  + JSON.stringify(err));
1195  });
1196  ```
1197
1198### setOAuthTokenVisibility<sup>8+</sup>
1199
1200setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback&lt;void&gt;): void
1201
1202Sets the visibility of an OAuth token to an app. This API uses an asynchronous callback to return the result.
1203
1204**System capability**: SystemCapability.Account.AppAccount
1205
1206**Parameters**
1207
1208| Name       | Type                       | Mandatory  | Description          |
1209| ---------- | ------------------------- | ---- | ------------ |
1210| name       | string                    | Yes   | Name of the target app account.    |
1211| authType   | string                    | Yes   | Authentication type.       |
1212| bundleName | string                    | Yes   | Bundle name of the app.|
1213| isVisible  | boolean                   | Yes   | Whether the OAuth token is visible to the app.       |
1214| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback invoked to return the result.    |
1215
1216**Example**
1217
1218  ```js
1219  const appAccountManager = account_appAccount.createAppAccountManager();
1220  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true, (err) => {
1221       console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
1222  });
1223  ```
1224
1225### setOAuthTokenVisibility<sup>8+</sup>
1226
1227setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise&lt;void&gt;
1228
1229Sets the visibility of an OAuth token to an app. This API uses a promise to return the result.
1230
1231**System capability**: SystemCapability.Account.AppAccount
1232
1233**Parameters**
1234
1235| Name       | Type     | Mandatory  | Description          |
1236| ---------- | ------- | ---- | ------------ |
1237| name       | string  | Yes   | Name of the target app account.    |
1238| authType   | string  | Yes   | Authentication type.       |
1239| bundleName | string  | Yes   | Bundle name of the app.|
1240| isVisible  | boolean | Yes   | Whether the OAuth token is visible to the app.       |
1241
1242**Parameters**
1243
1244| Type                 | Description                   |
1245| ------------------- | --------------------- |
1246| Promise&lt;void&gt; | Promise used to return the result.|
1247
1248**Example**
1249
1250  ```js
1251  const appAccountManager = account_appAccount.createAppAccountManager();
1252  appAccountManager.setOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", true).then(() => {
1253      console.log('setOAuthTokenVisibility successfully');
1254  }).catch((err) => {
1255      console.log('setOAuthTokenVisibility err: ' + JSON.stringify(err));
1256  });
1257  ```
1258
1259### checkOAuthTokenVisibility<sup>8+</sup>
1260
1261checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
1262
1263Checks whether an OAuth token is visible to an app. This API uses an asynchronous callback to return the result.
1264
1265**System capability**: SystemCapability.Account.AppAccount
1266
1267**Parameters**
1268
1269| Name       | Type                          | Mandatory  | Description           |
1270| ---------- | ---------------------------- | ---- | ------------- |
1271| name       | string                       | Yes   | Name of the target app account.     |
1272| authType   | string                       | Yes   | Authentication type.        |
1273| bundleName | string                       | Yes   | Bundle name of the app.|
1274| callback   | AsyncCallback&lt;boolean&gt; | Yes   | Callback invoked to return the result.     |
1275
1276**Example**
1277
1278  ```js
1279  const appAccountManager = account_appAccount.createAppAccountManager();
1280  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo", (err, data) => {
1281      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
1282      console.log('checkOAuthTokenVisibility isVisible: ' + data);
1283  });
1284  ```
1285
1286### checkOAuthTokenVisibility<sup>8+</sup>
1287
1288checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise&lt;boolean&gt;
1289
1290Checks whether an OAuth token is visible to an app. This API uses a promise to return the result.
1291
1292**System capability**: SystemCapability.Account.AppAccount
1293
1294**Parameters**
1295
1296| Name       | Type    | Mandatory  | Description           |
1297| ---------- | ------ | ---- | ------------- |
1298| name       | string | Yes   | Name of the target app account.     |
1299| authType   | string | Yes   | Authentication type.        |
1300| bundleName | string | Yes   | Bundle name of the app.|
1301
1302**Parameters**
1303
1304| Type                    | Description                   |
1305| ---------------------- | --------------------- |
1306| Promise&lt;boolean&gt; | Promise used to return the result.|
1307
1308**Example**
1309
1310  ```js
1311  const appAccountManager = account_appAccount.createAppAccountManager();
1312  appAccountManager.checkOAuthTokenVisibility("LiSi", "getSocialData", "com.example.ohos.accountjsdemo").then((data) => {
1313      console.log('checkOAuthTokenVisibility isVisible: ' + data);
1314  }).catch((err) => {
1315      console.log('checkOAuthTokenVisibility err: ' + JSON.stringify(err));
1316  });
1317  ```
1318
1319### getAllOAuthTokens<sup>8+</sup>
1320
1321getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt;): void
1322
1323Obtains all OAuth tokens visible to the caller for an app account. This API uses an asynchronous callback to return the result.
1324
1325**System capability**: SystemCapability.Account.AppAccount
1326
1327**Parameters**
1328
1329| Name     | Type                                      | Mandatory  | Description         |
1330| -------- | ---------------------------------------- | ---- | ----------- |
1331| name     | string                                   | Yes   | Name of the target app account.   |
1332| owner    | string                                   | Yes   | Bundle name of the app.|
1333| callback | AsyncCallback&lt;Array&lt;OAuthTokenInfo&gt;&gt; | Yes   | Callback invoked to return the result.   |
1334
1335**Example**
1336
1337  ```js
1338  const appAccountManager = account_appAccount.createAppAccountManager();
1339  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo", (err, data) => {
1340      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
1341      console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
1342  });
1343  ```
1344
1345### getAllOAuthTokens<sup>8+</sup>
1346
1347getAllOAuthTokens(name: string, owner: string): Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt;
1348
1349Obtains all OAuth tokens visible to the caller for an app account. This API uses a promise to return the result.
1350
1351**System capability**: SystemCapability.Account.AppAccount
1352
1353**Parameters**
1354
1355| Name  | Type    | Mandatory  | Description         |
1356| ----- | ------ | ---- | ----------- |
1357| name  | string | Yes   | Name of the target app account.   |
1358| owner | string | Yes   | Bundle name of the app.|
1359
1360**Parameters**
1361
1362| Type                                      | Description                   |
1363| ---------------------------------------- | --------------------- |
1364| Promise&lt;Array&lt;OAuthTokenInfo&gt;&gt; | Promise used to return the result.|
1365
1366**Example**
1367
1368  ```js
1369  const appAccountManager = account_appAccount.createAppAccountManager();
1370  appAccountManager.getAllOAuthTokens("LiSi", "com.example.ohos.accountjsdemo").then((data) => {
1371       console.log('getAllOAuthTokens data: ' + JSON.stringify(data));
1372  }).catch((err) => {
1373      console.log("getAllOAuthTokens err: "  + JSON.stringify(err));
1374  });
1375  ```
1376
1377### getOAuthList<sup>8+</sup>
1378
1379getOAuthList(name: string, authType: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
1380
1381Obtains a list of authorized OAuth tokens of an app account. This API uses an asynchronous callback to return the result.
1382
1383**System capability**: SystemCapability.Account.AppAccount
1384
1385**Parameters**
1386
1387| Name     | Type                                      | Mandatory  | Description         |
1388| -------- | ---------------------------------------- | ---- | ----------- |
1389| name     | string                                   | Yes   | Name of the target app account.   |
1390| owner    | string                                   | Yes   | Bundle name of the app.|
1391| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback invoked to return the result.   |
1392
1393**Example**
1394
1395  ```js
1396  const appAccountManager = account_appAccount.createAppAccountManager();
1397  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData", (err, data) => {
1398       console.log('getOAuthList err: ' + JSON.stringify(err));
1399       console.log('getOAuthList data: ' + JSON.stringify(data));
1400  });
1401  ```
1402
1403### getOAuthList<sup>8+</sup>
1404
1405getOAuthList(name: string, authType: string): Promise&lt;Array&lt;string&gt;&gt;
1406
1407Obtains a list of authorized OAuth tokens of an app account. This API uses a promise to return the result.
1408
1409**System capability**: SystemCapability.Account.AppAccount
1410
1411**Parameters**
1412
1413| Name  | Type    | Mandatory  | Description         |
1414| ----- | ------ | ---- | ----------- |
1415| name  | string | Yes   | Name of the target app account.   |
1416| owner | string | Yes   | Bundle name of the app.|
1417
1418**Parameters**
1419
1420| Type                                | Description                   |
1421| ---------------------------------- | --------------------- |
1422| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
1423
1424**Example**
1425
1426  ```js
1427  const appAccountManager = account_appAccount.createAppAccountManager();
1428  appAccountManager.getOAuthList("com.example.ohos.accountjsdemo", "getSocialData").then((data) => {
1429       console.log('getOAuthList data: ' + JSON.stringify(data));
1430  }).catch((err) => {
1431      console.log("getOAuthList err: "  + JSON.stringify(err));
1432  });
1433  ```
1434
1435### getAuthenticatorCallback<sup>8+</sup>
1436
1437getAuthenticatorCallback(sessionId: string, callback: AsyncCallback&lt;AuthenticatorCallback&gt;): void
1438
1439Obtains the authenticator callback for a session. This API uses an asynchronous callback to return the result.
1440
1441**System capability**: SystemCapability.Account.AppAccount
1442
1443**Parameters**
1444
1445| Name      | Type                                      | Mandatory  | Description      |
1446| --------- | ---------------------------------------- | ---- | -------- |
1447| sessionId | string                                   | Yes   | ID of the session to authenticate.|
1448| callback  | AsyncCallback&lt;AuthenticatorCallback&gt; | Yes   | Callback invoked to return the result.|
1449
1450**Example**
1451
1452  ```js
1453  const appAccountManager = account_appAccount.createAppAccountManager();
1454  featureAbility.getWant((err, want) => {
1455    var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
1456    appAccountManager.getAuthenticatorCallback(sessionId, (err, callback) => {
1457        if (err.code != account_appAccount.ResultCode.SUCCESS) {
1458            console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1459            return;
1460        }
1461        var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1462                      [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1463                      [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1464                      [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1465        callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1466    });
1467  });
1468  ```
1469
1470### getAuthenticatorCallback<sup>8+</sup>
1471
1472getAuthenticatorCallback(sessionId: string): Promise&lt;AuthenticatorCallback&gt;
1473
1474Obtains the authenticator callback for a session. This API uses a promise to return the result.
1475
1476**System capability**: SystemCapability.Account.AppAccount
1477
1478**Parameters**
1479
1480| Name      | Type    | Mandatory  | Description      |
1481| --------- | ------ | ---- | -------- |
1482| sessionId | string | Yes   | ID of the session to authenticate.|
1483
1484**Parameters**
1485
1486| Type                                  | Description                   |
1487| ------------------------------------ | --------------------- |
1488| Promise&lt;AuthenticatorCallback&gt; | Promise used to return the result.|
1489
1490**Example**
1491
1492  ```js
1493  const appAccountManager = account_appAccount.createAppAccountManager();
1494  featureAbility.getWant().then((want) => {
1495      var sessionId = want.parameters[account_appAccount.Constants.KEY_SESSION_ID];
1496      appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
1497          var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1498                        [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1499                        [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1500                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1501          callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1502      }).catch((err) => {
1503          console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1504      });
1505  }).catch((err) => {
1506      console.log("getWant err: "  + JSON.stringify(err));
1507  });
1508  ```
1509
1510### getAuthenticatorInfo<sup>8+</sup>
1511
1512getAuthenticatorInfo(owner: string, callback: AsyncCallback&lt;AuthenticatorInfo&gt;): void
1513
1514Obtains authenticator information of an app account. This method uses an asynchronous callback to return the result.
1515
1516**System capability**: SystemCapability.Account.AppAccount
1517
1518**Parameters**
1519
1520| Name     | Type                                    | Mandatory  | Description         |
1521| -------- | -------------------------------------- | ---- | ----------- |
1522| owner    | string                                 | Yes   | Bundle name of the app.|
1523| callback | AsyncCallback&lt;AuthenticatorInfo&gt; | Yes   | Callback invoked to return the result.   |
1524
1525**Example**
1526
1527  ```js
1528  const appAccountManager = account_appAccount.createAppAccountManager();
1529  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo", (err, data) => {
1530      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
1531      console.log('getAuthenticatorInfo data: ' + JSON.stringify(data));
1532  });
1533  ```
1534
1535### getAuthenticatorInfo<sup>8+</sup>
1536
1537getAuthenticatorInfo(owner: string): Promise&lt;AuthenticatorInfo&gt;
1538
1539Obtains authenticator information of an app account. This API uses a promise to return the result.
1540
1541**System capability**: SystemCapability.Account.AppAccount
1542
1543**Parameters**
1544
1545| Name  | Type    | Mandatory  | Description         |
1546| ----- | ------ | ---- | ----------- |
1547| owner | string | Yes   | Bundle name of the app.|
1548
1549**Parameters**
1550
1551| Type                              | Description                   |
1552| -------------------------------- | --------------------- |
1553| Promise&lt;AuthenticatorInfo&gt; | Promise used to return the result.|
1554
1555**Example**
1556
1557  ```js
1558  const appAccountManager = account_appAccount.createAppAccountManager();
1559  appAccountManager.getAuthenticatorInfo("com.example.ohos.accountjsdemo").then((data) => {
1560       console.log('getAuthenticatorInfo: ' + JSON.stringify(data));
1561  }).catch((err) => {
1562      console.log("getAuthenticatorInfo err: "  + JSON.stringify(err));
1563  });
1564  ```
1565
1566## AppAccountInfo
1567
1568Defines app account information.
1569
1570**System capability**: SystemCapability.Account.AppAccount
1571
1572| Name  | Type    | Mandatory  | Description         |
1573| ----- | ------ | ---- | ----------- |
1574| owner | string | Yes   | Bundle name of the app.|
1575| name  | string | Yes   | Name of the app account.   |
1576
1577## OAuthTokenInfo<sup>8+</sup>
1578
1579Defines OAuth token information.
1580
1581**System capability**: SystemCapability.Account.AppAccount
1582
1583| Name     | Type    | Mandatory  | Description      |
1584| -------- | ------ | ---- | -------- |
1585| authType | string | Yes   | Authentication type.|
1586| token    | string | Yes   | Value of the token.  |
1587
1588## AuthenticatorInfo<sup>8+</sup>
1589
1590Defines OAuth authenticator information.
1591
1592**System capability**: SystemCapability.Account.AppAccount
1593
1594| Name    | Type    | Mandatory  | Description        |
1595| ------- | ------ | ---- | ---------- |
1596| owner   | string | Yes   | Owner of the authenticator. The value is the bundle name of the app.|
1597| iconId  | number | Yes   | ID of the authenticator icon. |
1598| labelId | number | Yes   | ID of the authenticator label. |
1599
1600## Constants<sup>8+</sup>
1601
1602Enumerates the constants.
1603
1604**System capability**: SystemCapability.Account.AppAccount
1605
1606| Name                           | Default Value                   | Description           |
1607| ----------------------------- | ---------------------- | ------------- |
1608| ACTION_ADD_ACCOUNT_IMPLICITLY | "addAccountImplicitly" | Operation for implicitly adding an account. |
1609| ACTION_AUTHENTICATE           | "authenticate"         | Authentication operation.     |
1610| KEY_NAME                      | "name"                 | App account name. |
1611| KEY_OWNER                     | "owner"                | App account owner.|
1612| KEY_TOKEN                     | "token"                | OAuth token.     |
1613| KEY_ACTION                    | "action"               | Action.     |
1614| KEY_AUTH_TYPE                 | "authType"             | Authentication type.   |
1615| KEY_SESSION_ID                | "sessionId"            | Session ID.   |
1616| KEY_CALLER_PID                | "callerPid"            | Caller process ID (PID). |
1617| KEY_CALLER_UID                | "callerUid"            | Caller user ID (UID). |
1618| KEY_CALLER_BUNDLE_NAME        | "callerBundleName"     | Caller bundle name.  |
1619
1620## ResultCode<sup>8+</sup>
1621
1622Enumerates the result codes.
1623
1624**System capability**: SystemCapability.Account.AppAccount
1625
1626| Name                                 | Default Value  | Description          |
1627| ----------------------------------- | ----- | ------------ |
1628| SUCCESS                             | 0     | The operation is successful.     |
1629| ERROR_ACCOUNT_NOT_EXIST             | 10001 | The app account does not exist.  |
1630| ERROR_APP_ACCOUNT_SERVICE_EXCEPTION | 10002 | The app account service is abnormal. |
1631| ERROR_INVALID_PASSWORD              | 10003 | The password is invalid.     |
1632| ERROR_INVALID_REQUEST               | 10004 | The request is invalid.     |
1633| ERROR_INVALID_RESPONSE              | 10005 | The response is invalid.     |
1634| ERROR_NETWORK_EXCEPTION             | 10006 | The network is abnormal.     |
1635| ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST | 10007 | The authenticator does not exist.   |
1636| ERROR_OAUTH_CANCELED                | 10008 | The authentication is canceled.     |
1637| ERROR_OAUTH_LIST_TOO_LARGE          | 10009 | The size of the OAuth list exceeds the limit. |
1638| ERROR_OAUTH_SERVICE_BUSY            | 10010 | The OAuth service is busy. |
1639| ERROR_OAUTH_SERVICE_EXCEPTION       | 10011 | The OAuth service is abnormal. |
1640| ERROR_OAUTH_SESSION_NOT_EXIST       | 10012 | The session to be authenticated does not exist.  |
1641| ERROR_OAUTH_TIMEOUT                 | 10013 | The authentication timed out.     |
1642| ERROR_OAUTH_TOKEN_NOT_EXIST         | 10014 | The OAuth token does not exist.|
1643| ERROR_OAUTH_TOKEN_TOO_MANY          | 10015 | The number of OAuth tokens reaches the limit. |
1644| ERROR_OAUTH_UNSUPPORT_ACTION        | 10016 | The authentication operation is not supported. |
1645| ERROR_OAUTH_UNSUPPORT_AUTH_TYPE     | 10017 | The authentication type is not supported. |
1646| ERROR_PERMISSION_DENIED             | 10018 | The required permission is missing.     |
1647
1648## AuthenticatorCallback<sup>8+</sup>
1649
1650Provides OAuth authenticator callbacks.
1651
1652### onResult<sup>8+</sup>
1653
1654onResult: (code: number, result: {[key: string]: any}) =&gt; void
1655
1656Called back to send the authentication result.
1657
1658**System capability**: SystemCapability.Account.AppAccount
1659
1660**Parameters**
1661| Name   | Type                  | Mandatory  | Description    |
1662| ------ | -------------------- | ---- | ------ |
1663| code   | number               | Yes   | Authentication result code.|
1664| result | {[key: string]: any} | Yes   | Authentication result. |
1665
1666**Example**
1667
1668  ```js
1669  const appAccountManager = account_appAccount.createAppAccountManager();
1670  var sessionId = "1234";
1671  appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => {
1672      var result = {[account_appAccount.Constants.KEY_NAME]: "LiSi",
1673                    [account_appAccount.Constants.KEY_OWNER]: "com.example.ohos.accountjsdemo",
1674                    [account_appAccount.Constants.KEY_AUTH_TYPE]: "getSocialData",
1675                    [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1676      callback.OnResult(account_appAccount.ResultCode.SUCCESS, result);
1677  }).catch((err) => {
1678      console.log("getAuthenticatorCallback err: "  + JSON.stringify(err));
1679  });
1680  ```
1681
1682### onRequestRedirected<sup>8+</sup>
1683
1684onRequestRedirected: (request: Want) =&gt; void
1685
1686Called back to redirect an authentication request.
1687
1688**System capability**: SystemCapability.Account.AppAccount
1689
1690**Parameters**
1691| Name    | Type  | Mandatory  | Description        |
1692| ------- | ---- | ---- | ---------- |
1693| request | Want | Yes   | Request to be redirected.|
1694
1695**Example**
1696
1697  ```js
1698  class MyAuthenticator extends account_appAccount.Authenticator {
1699      addAccountImplicitly(authType, callerBundleName, options, callback) {
1700          callback.onRequestRedirected({
1701              bundleName: "com.example.ohos.accountjsdemo",
1702              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
1703          });
1704      }
1705
1706      authenticate(name, authType, callerBundleName, options, callback) {
1707          var result = {[account_appAccount.Constants.KEY_NAME]: name,
1708                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
1709                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1710          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
1711      }
1712  }
1713  ```
1714
1715## Authenticator<sup>8+</sup>
1716
1717OAuth authenticator base class.
1718
1719### addAccountImplicitly<sup>8+</sup>
1720
1721addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
1722
1723Implicitly adds an app account based on the specified authentication type and options. This API uses an asynchronous callback to return the result.
1724
1725**System capability**: SystemCapability.Account.AppAccount
1726
1727**Parameters**
1728| Name             | Type                   | Mandatory  | Description             |
1729| ---------------- | --------------------- | ---- | --------------- |
1730| authType         | string                | Yes   | Authentication type.     |
1731| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
1732| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
1733| callback         | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
1734
1735### authenticate<sup>8+</sup>
1736
1737authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void
1738
1739Authenticates an app account to obtain the OAuth token. This API uses an asynchronous callback to return the result.
1740
1741**System capability**: SystemCapability.Account.AppAccount
1742
1743**Parameters**
1744| Name             | Type                   | Mandatory  | Description             |
1745| ---------------- | --------------------- | ---- | --------------- |
1746| name             | string                | Yes   | Name of the target app account.       |
1747| authType         | string                | Yes   | Authentication type.     |
1748| callerBundleName | string                | Yes   | Bundle name of the authentication requester.      |
1749| options          | {[key: string]: any}  | Yes   | Options for the authentication.     |
1750| callback         | AuthenticatorCallback | Yes   | Authenticator callback invoked to return the authentication result.|
1751
1752**Example**
1753
1754  ```js
1755  class MyAuthenticator extends account_appAccount.Authenticator {
1756      addAccountImplicitly(authType, callerBundleName, options, callback) {
1757          callback.onRequestRedirected({
1758              bundleName: "com.example.ohos.accountjsdemo",
1759              abilityName: "com.example.ohos.accountjsdemo.LoginAbility",
1760          });
1761      }
1762
1763      authenticate(name, authType, callerBundleName, options, callback) {
1764          var result = {[account_appAccount.Constants.KEY_NAME]: name,
1765                        [account_appAccount.Constants.KEY_AUTH_TYPE]: authType,
1766                        [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"};
1767          callback.onResult(account_appAccount.ResultCode.SUCCESS, result);
1768      }
1769  }
1770
1771  export default {
1772      onConnect(want) {
1773          return new MyAuthenticator();
1774      }
1775  }
1776  ```
1777