1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback, Callback } from './basic'; 17import Want from './@ohos.app.ability.Want'; 18import rpc from './@ohos.rpc' 19 20/** 21 * This module provides the capability to manage application accounts. 22 * @syscap SystemCapability.Account.AppAccount 23 * @since 7 24 */ 25declare namespace appAccount { 26 /** 27 * Obtains the AppAccountManager instance. 28 * @returns Returns the instance of the AppAccountManager. 29 * @syscap SystemCapability.Account.AppAccount 30 * @since 7 31 */ 32 function createAppAccountManager(): AppAccountManager; 33 34 /** 35 * Provides methods for managing application accounts. 36 * @name AppAccountManager 37 * @syscap SystemCapability.Account.AppAccount 38 * @since 7 39 */ 40 interface AppAccountManager { 41 /** 42 * Adds the account name and extra information of this application to the account management service. 43 * <p> 44 * Only the owner of the application account has the permission to call this method. 45 * @param name Indicates the name of the application account to add. 46 * @param extraInfo Indicates the extra information of the application account to add. 47 * The extra information cannot be sensitive information of the application account. 48 * @returns void. 49 * @since 7 50 * @deprecated since 9 51 * @useinstead appAccount.AppAccountManager#createAccount 52 */ 53 addAccount(name: string, callback: AsyncCallback<void>): void; 54 addAccount(name: string, extraInfo: string, callback: AsyncCallback<void>): void; 55 addAccount(name: string, extraInfo?: string): Promise<void>; 56 57 /** 58 * Creates the account name and extra information of this application to the account management service. 59 * <p> 60 * Only the owner of the application account has the permission to call this method. 61 * @param name Indicates the name of the application account to add. 62 * @param options Indicates the extra information of the application account to add. 63 * The extra information cannot be sensitive information of the application account. 64 * @returns void. 65 * @throws {BusinessError} 401 - the parameter check failed. 66 * @throws {BusinessError} 12300001 - system service exception. 67 * @throws {BusinessError} 12300002 - invalid name or options. 68 * @throws {BusinessError} 12300004 - the account indicated by name already exist. 69 * @throws {BusinessError} 12300007 - the account number has reached the upper limit. 70 * @since 9 71 */ 72 createAccount(name: string, callback: AsyncCallback<void>): void; 73 createAccount(name: string, options: CreateAccountOptions, callback: AsyncCallback<void>): void; 74 createAccount(name: string, options?: CreateAccountOptions): Promise<void>; 75 76 /** 77 * Adds an application account of a specified owner implicitly. 78 * @param owner Indicates the account owner of your application or third-party applications. 79 * @param authType Indicates the authentication type. 80 * @param options Indicates the authenticator-specific options for the request. 81 * @param callback Indicates the authenticator callback. 82 * @returns void. 83 * @since 8 84 * @deprecated since 9 85 * @useinstead appAccount.AppAccountManager#createAccountImplicitly 86 */ 87 addAccountImplicitly(owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; 88 89 /** 90 * Creates an application account of a specified owner implicitly. 91 * @param owner Indicates the account owner of your application or third-party applications. 92 * @param options Indicates the authenticator-specific options for the request. 93 * @param callback Indicates the authenticator callback. 94 * @returns void. 95 * @throws {BusinessError} 401 - the parameter check failed. 96 * @throws {BusinessError} 12300001 - system service exception. 97 * @throws {BusinessError} 12300002 - invalid owner or options. 98 * @throws {BusinessError} 12300007 - the account number has reached the upper limit. 99 * @throws {BusinessError} 12300010 - account service busy. 100 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 101 * @throws {BusinessError} 12300114 - authenticator service exception. 102 * @since 9 103 */ 104 createAccountImplicitly(owner: string, callback: AuthCallback): void; 105 createAccountImplicitly(owner: string, options: CreateAccountImplicitlyOptions, callback: AuthCallback): void; 106 107 /** 108 * Deletes an application account from the account management service. 109 * <p> 110 * Only the owner of the application account has the permission to call this method. 111 * @param name Indicates the name of the application account to delete. 112 * @returns void. 113 * @since 7 114 * @deprecated since 9 115 * @useinstead appAccount.AppAccountManager#removeAccount 116 */ 117 deleteAccount(name: string, callback: AsyncCallback<void>): void; 118 deleteAccount(name: string): Promise<void>; 119 120 /** 121 * Removes an application account from the account management service. 122 * <p> 123 * Only the owner of the application account has the permission to call this method. 124 * @param name Indicates the name of the application account to delete. 125 * @returns void. 126 * @throws {BusinessError} 401 - the parameter check failed. 127 * @throws {BusinessError} 12300001 - system service exception. 128 * @throws {BusinessError} 12300002 - invalid name. 129 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 130 * @since 9 131 */ 132 removeAccount(name: string, callback: AsyncCallback<void>): void; 133 removeAccount(name: string): Promise<void>; 134 135 /** 136 * Disables a third-party application with the specified bundle name from 137 * accessing the given application account. 138 * @param name Indicates the name of the application account to disable access from 139 * the third-party application. 140 * @param bundleName Indicates the bundle name of the third-party application. 141 * @returns void. 142 * @since 7 143 * @deprecated since 9 144 * @useinstead appAccount.AppAccountManager#setAppAccess 145 */ 146 disableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; 147 disableAppAccess(name: string, bundleName: string): Promise<void>; 148 149 /** 150 * Enables a third-party application with the specified bundle name to access the given application 151 * account for data query and listening. 152 * @param name Indicates the name of the application account. 153 * @param bundleName Indicates the bundle name of the third-party application. 154 * @returns void. 155 * @since 7 156 * @deprecated since 9 157 * @useinstead appAccount.AppAccountManager#setAppAccess 158 */ 159 enableAppAccess(name: string, bundleName: string, callback: AsyncCallback<void>): void; 160 enableAppAccess(name: string, bundleName: string): Promise<void>; 161 162 /** 163 * Sets a third-party application with the specified bundle name to access the given application 164 * account for data query and listening. 165 * @param name Indicates the name of the application account. 166 * @param bundleName Indicates the bundle name of the third-party application. 167 * @param isAccessible Indicates the accessibility flag, true for accessible, false for inaccessible. 168 * @returns void. 169 * @throws {BusinessError} 401 - the parameter check failed. 170 * @throws {BusinessError} 12300001 - system service exception. 171 * @throws {BusinessError} 12300002 - invalid name or bundle name. 172 * @throws {BusinessError} 12300003 - the account indicated by localId dose not exist. 173 * @throws {BusinessError} 12400001 - the application indicated by bundlename does not exist. 174 * @since 9 175 */ 176 setAppAccess(name: string, bundleName: string, isAccessible: boolean, callback: AsyncCallback<void>): void; 177 setAppAccess(name: string, bundleName: string, isAccessible: boolean): Promise<void>; 178 179 /** 180 * Checks whether a third-party application with the specified bundle name is allowed to access 181 * the given application account for data query and listening. 182 * @param name Indicates the name of the application account. 183 * @param bundleName Indicates the bundle name of the third-party application. 184 * @returns void. 185 * @throws {BusinessError} 401 - the parameter check failed. 186 * @throws {BusinessError} 12300001 - system service exception. 187 * @throws {BusinessError} 12300002 - invalid name or bundle name. 188 * @throws {BusinessError} 12300003 - the account indicated by localId dose not exist. 189 * @since 9 190 */ 191 checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void; 192 checkAppAccess(name: string, bundleName: string): Promise<boolean>; 193 194 /** 195 * Checks whether a specified application account allows application data synchronization. 196 * <p> 197 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 198 * through the distributed networking. On the connected devices, you can call this method to check 199 * whether application data can be synchronized. 200 * <p> 201 * @permission ohos.permission.DISTRIBUTED_DATASYNC 202 * @param name Indicates the name of the application account. 203 * @returns Returns {@code true} if application data synchronization is allowed; returns {@code false} otherwise. 204 * @since 7 205 * @deprecated since 9 206 * @useinstead appAccount.AppAccountManager#checkDataSyncEnabled 207 */ 208 checkAppAccountSyncEnable(name: string, callback: AsyncCallback<boolean>): void; 209 checkAppAccountSyncEnable(name: string): Promise<boolean>; 210 211 /** 212 * Checks whether application data synchronization is enabled for the specified account. 213 * <p> 214 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 215 * through the distributed networking. On the connected devices, you can call this method to check 216 * whether application data can be synchronized. 217 * <p> 218 * @permission ohos.permission.DISTRIBUTED_DATASYNC 219 * @param name Indicates the name of the application account. 220 * @returns Returns {@code true} if application data synchronization is allowed; returns {@code false} otherwise. 221 * @throws {BusinessError} 201 - permission denied. 222 * @throws {BusinessError} 401 - the parameter check failed. 223 * @throws {BusinessError} 12300001 - system service exception. 224 * @throws {BusinessError} 12300002 - invalid name. 225 * @throws {BusinessError} 12300003 - the account indicated by localId dose not exist. 226 * @since 9 227 */ 228 checkDataSyncEnabled(name: string, callback: AsyncCallback<boolean>): void; 229 checkDataSyncEnabled(name: string): Promise<boolean>; 230 231 /** 232 * Sets the credential for this application account. 233 * @param name Indicates the name of the application account. 234 * @param credentialType Indicates the type of the credential to set. 235 * @param credential Indicates the credential to set. 236 * @returns void. 237 * @since 7 238 * @deprecated since 9 239 * @useinstead appAccount.AppAccountManager#setCredential 240 */ 241 setAccountCredential(name: string, credentialType: string, credential: string, 242 callback: AsyncCallback<void>): void; 243 setAccountCredential(name: string, credentialType: string, credential: string): Promise<void>; 244 245 /** 246 * Sets the credential for this application account. 247 * @param name Indicates the name of the application account. 248 * @param credentialType Indicates the type of the credential to set. 249 * @param credential Indicates the credential to set. 250 * @returns void. 251 * @throws {BusinessError} 401 - the parameter check failed. 252 * @throws {BusinessError} 12300001 - system service exception. 253 * @throws {BusinessError} 12300002 - invalid name, credentialType or credential. 254 * @throws {BusinessError} 12300003 - the account indicated by localId dose not exist. 255 * @since 9 256 */ 257 setCredential(name: string, credentialType: string, credential: string, 258 callback: AsyncCallback<void>): void; 259 setCredential(name: string, credentialType: string, credential: string): Promise<void>; 260 261 /** 262 * Sets extra information for this application account. 263 * <p> 264 * You can call this method when you forget the extra information of your application account or 265 * need to modify the extra information. 266 * @param name Indicates the name of the application account. 267 * @param extraInfo Indicates the extra information to set. 268 * @returns void. 269 * @since 7 270 * @deprecated since 9 271 * @useinstead appAccount.AppAccountManager#setCustomData 272 */ 273 setAccountExtraInfo(name: string, extraInfo: string, callback: AsyncCallback<void>): void; 274 setAccountExtraInfo(name: string, extraInfo: string): Promise<void>; 275 276 /** 277 * Sets whether a specified application account allows application data synchronization. 278 * <p> 279 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 280 * through the distributed networking. On the connected devices, you can call this method to set whether to 281 * allow cross-device data synchronization. If synchronization is allowed, application data can be synchronized 282 * among these devices in the event of any changes related to the application account. 283 * If synchronization is not allowed, the application data is stored only on the local device. 284 * <p> 285 * <b>Application account-related changes</b>: adding or deleting an application account, setting extra 286 * information (such as updating a token), and setting data associated with this application account 287 * <p> 288 * <b>Application data that can be synchronized</b>: application account name, token, 289 * and data associated with this application account 290 * <p> 291 * @permission ohos.permission.DISTRIBUTED_DATASYNC 292 * @param name Indicates the name of the application account. 293 * @param isEnable Specifies whether to allow application data synchronization. 294 * @returns void. 295 * @since 7 296 * @deprecated since 9 297 * @useinstead appAccount.AppAccountManager#setDataSyncEnabled 298 */ 299 setAppAccountSyncEnable(name: string, isEnable: boolean, callback: AsyncCallback<void>): void; 300 setAppAccountSyncEnable(name: string, isEnable: boolean): Promise<void>; 301 302 /** 303 * Sets whether a specified application account enables application data synchronization. 304 * <p> 305 * If the same OHOS account has logged in to multiple devices, these devices constitute a super device 306 * through the distributed networking. On the connected devices, you can call this method to set whether to 307 * enable cross-device data synchronization. If synchronization is enabled, application data can be synchronized 308 * among these devices in the event of any changes related to the application account. 309 * If synchronization is not enabled, the application data is stored only on the local device. 310 * <p> 311 * <b>Application account-related changes</b>: adding or deleting an application account, setting extra 312 * information (such as updating a token), and setting data associated with this application account 313 * <p> 314 * <b>Application data that can be synchronized</b>: application account name, token, 315 * and data associated with this application account 316 * <p> 317 * @permission ohos.permission.DISTRIBUTED_DATASYNC 318 * @param name Indicates the name of the application account. 319 * @param isEnabled Specifies whether to enable application data synchronization. 320 * @returns void. 321 * @throws {BusinessError} 201 - permission denied. 322 * @throws {BusinessError} 401 - the parameter check failed. 323 * @throws {BusinessError} 12300001 - system service exception. 324 * @throws {BusinessError} 12300002 - invalid name. 325 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 326 * @since 9 327 */ 328 setDataSyncEnabled(name: string, isEnabled: boolean, callback: AsyncCallback<void>): void; 329 setDataSyncEnabled(name: string, isEnabled: boolean): Promise<void>; 330 331 /** 332 * Sets data associated with this application account. 333 * @param name Indicates the name of the application account. 334 * @param key Indicates the key of the data to set. The key can be customized. 335 * @param value Indicates the value of the data to set. 336 * @returns void. 337 * @since 7 338 * @deprecated since 9 339 * @useinstead appAccount.AppAccountManager#setCustomData 340 */ 341 setAssociatedData(name: string, key: string, value: string, callback: AsyncCallback<void>): void; 342 setAssociatedData(name: string, key: string, value: string): Promise<void>; 343 344 /** 345 * Sets data associated with this application account. 346 * @param name Indicates the name of the application account. 347 * @param key Indicates the key of the data to set. The key can be customized. 348 * @param value Indicates the value of the data to set. 349 * @returns void. 350 * @throws {BusinessError} 401 - the parameter check failed. 351 * @throws {BusinessError} 12300001 - system service exception. 352 * @throws {BusinessError} 12300002 - invalid name, key or value. 353 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 354 * @throws {BusinessError} 12400003 - the number of customized data has reached the upper limit. 355 * @since 9 356 */ 357 setCustomData(name: string, key: string, value: string, callback: AsyncCallback<void>): void; 358 setCustomData(name: string, key: string, value: string): Promise<void>; 359 360 /** 361 * Obtains information about all accessible accounts. 362 * <p> 363 * This method applies to the following accounts: 364 * <ul> 365 * <li>Accounts of this application.</li> 366 * <li>Accounts of third-party applications. To obtain such information, 367 * your application must have gained authorization from the third-party applications.</li> 368 * </ul> 369 * @permission ohos.permission.GET_ALL_APP_ACCOUNTS 370 * @returns Returns a list of application accounts. 371 * @since 7 372 * @deprecated since 9 373 * @useinstead appAccount.AppAccountManager#getAllAccounts 374 */ 375 getAllAccessibleAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void; 376 getAllAccessibleAccounts(): Promise<Array<AppAccountInfo>>; 377 378 /** 379 * Obtains information about all accessible accounts. 380 * <p> 381 * This method applies to the following accounts: 382 * <ul> 383 * <li>Accounts of this application.</li> 384 * <li>Accounts of third-party applications. To obtain such information, 385 * your application must have gained authorization from the third-party applications.</li> 386 * </ul> 387 * @returns Returns a list of application accounts. 388 * @throws {BusinessError} 401 - the parameter check failed. 389 * @throws {BusinessError} 12300001 - system service exception. 390 * @since 9 391 */ 392 getAllAccounts(callback: AsyncCallback<Array<AppAccountInfo>>): void; 393 getAllAccounts(): Promise<Array<AppAccountInfo>>; 394 395 /** 396 * Obtains information about all accounts of a specified account owner. 397 * <p> 398 * This method applies to the following accounts: 399 * <ul> 400 * <li>Accounts of this application.</li> 401 * <li>Accounts of third-party applications. To obtain such information, 402 * your application must have gained authorization from the third-party applications.</li> 403 * </ul> 404 * @permission ohos.permission.GET_ALL_APP_ACCOUNTS 405 * @param owner Indicates the account owner of your application or third-party applications. 406 * @returns Returns a list of application accounts. 407 * @since 7 408 * @deprecated since 9 409 * @useinstead appAccount.AppAccountManager#getAccountsByOwner 410 */ 411 getAllAccounts(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void; 412 getAllAccounts(owner: string): Promise<Array<AppAccountInfo>>; 413 414 /** 415 * Gets information about all accounts of a specified account owner. 416 * <p> 417 * This method applies to the following accounts: 418 * <ul> 419 * <li>Accounts of this application.</li> 420 * <li>Accounts of third-party applications. To obtain such information, 421 * your application must have gained authorization from the third-party applications.</li> 422 * </ul> 423 * @param owner Indicates the account owner of your application or third-party applications. 424 * @returns Returns a list of application accounts. 425 * @throws {BusinessError} 401 - the parameter check failed. 426 * @throws {BusinessError} 12300001 - system service exception. 427 * @throws {BusinessError} 12300002 - invalid owner. 428 * @throws {BusinessError} 12400001 - the application indicated by bundle name does not exist. 429 * @since 9 430 */ 431 getAccountsByOwner(owner: string, callback: AsyncCallback<Array<AppAccountInfo>>): void; 432 getAccountsByOwner(owner: string): Promise<Array<AppAccountInfo>>; 433 434 /** 435 * Obtains the credential of this application account. 436 * @param name Indicates the name of the application account. 437 * @param credentialType Indicates the type of the credential to obtain. 438 * @returns Returns the credential of the application account. 439 * @since 7 440 * @deprecated since 9 441 * @useinstead appAccount.AppAccountManager#getCredential 442 */ 443 getAccountCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void; 444 getAccountCredential(name: string, credentialType: string): Promise<string>; 445 446 /** 447 * Obtains the credential of this application account. 448 * @param name Indicates the name of the application account. 449 * @param credentialType Indicates the type of the credential to obtain. 450 * @returns Returns the credential of the application account. 451 * @throws {BusinessError} 401 - the parameter check failed. 452 * @throws {BusinessError} 12300001 - system service exception. 453 * @throws {BusinessError} 12300002 - invalid name or credentialType. 454 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 455 * @throws {BusinessError} 12300102 - credential does not exist. 456 * @since 9 457 */ 458 getCredential(name: string, credentialType: string, callback: AsyncCallback<string>): void; 459 getCredential(name: string, credentialType: string): Promise<string>; 460 461 /** 462 * Obtains extra information of this application account. 463 * @param name Indicates the name of the application account. 464 * @returns Returns the extra information of the account; returns {@code null} in other scenarios, 465 * for example, if the account does not exist. 466 * @since 7 467 * @deprecated since 9 468 * @useinstead appAccount.AppAccountManager#getCustomData 469 */ 470 getAccountExtraInfo(name: string, callback: AsyncCallback<string>): void; 471 getAccountExtraInfo(name: string): Promise<string>; 472 473 /** 474 * Obtains data associated with this application account. 475 * @param name Indicates the name of the application account. 476 * @param key Indicates the key of the data to obtain. 477 * @returns Returns the associated data of the application account. 478 * @since 7 479 * @deprecated since 9 480 * @useinstead appAccount.AppAccountManager#getCustomData 481 */ 482 getAssociatedData(name: string, key: string, callback: AsyncCallback<string>): void; 483 getAssociatedData(name: string, key: string): Promise<string>; 484 485 /** 486 * Obtains data associated with this application account. 487 * @param name Indicates the name of the application account. 488 * @param key Indicates the key of the data to obtain. 489 * @returns Returns the associated data of the application account. 490 * @throws {BusinessError} 401 - the parameter check failed. 491 * @throws {BusinessError} 12300001 - system service exception. 492 * @throws {BusinessError} 12300002 - invalid name or key. 493 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 494 * @throws {BusinessError} 12400002 - the customData does not exist. 495 * @since 9 496 */ 497 getCustomData(name: string, key: string, callback: AsyncCallback<string>): void; 498 getCustomData(name: string, key: string): Promise<string>; 499 500 /** 501 * Obtains data associated with the specified account synchronously. 502 * @param name Indicates the name of the application account. 503 * @param key Indicates the key of the data to obtain. 504 * @returns Returns the associated data of the application account. 505 * @throws {BusinessError} 401 - the parameter check failed. 506 * @throws {BusinessError} 12300001 - system service exception. 507 * @throws {BusinessError} 12300002 - invalid name or key. 508 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 509 * @throws {BusinessError} 12400002 - the customData does not exist. 510 * @since 9 511 */ 512 getCustomDataSync(name: string, key: string): string; 513 514 /** 515 * Subscribes to the change events of accounts of the specified owners. 516 * <p> 517 * When the account owner updates the account, the subscriber will receive a notification 518 * about the account change event. 519 * @param owners Indicates the account owners, which are specified 520 * by {@link AppAccount#AppAccount(String name, String owner)}. 521 * @returns void 522 * @since 7 523 * @deprecated since 9 524 * @useinstead appAccount.AppAccountManager#on 525 */ 526 on(type: 'change', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void; 527 528 /** 529 * Subscribes to the change events of accounts of the specified owners. 530 * <p> 531 * When the account owner updates the account, the subscriber will receive a notification 532 * about the account change event. 533 * @param owners Indicates the account owners, which are specified 534 * by {@link AppAccount#AppAccount(String name, String owner)}. 535 * @returns void 536 * @throws {BusinessError} 401 - the parameter check failed. 537 * @throws {BusinessError} 12300001 - system service exception. 538 * @throws {BusinessError} 12300002 - invalid type or owners. 539 * @throws {BusinessError} 12300011 - the callback has been registered. 540 * @throws {BusinessError} 12400001 - the application indicated by owner does not exist. 541 * @since 9 542 */ 543 on(type: 'accountChange', owners: Array<string>, callback: Callback<Array<AppAccountInfo>>): void; 544 545 /** 546 * Unsubscribes from account events. 547 * @returns void 548 * @since 7 549 * @deprecated since 9 550 * @useinstead appAccount.AppAccountManager#off 551 */ 552 off(type: 'change', callback?: Callback<Array<AppAccountInfo>>): void; 553 554 /** 555 * Unsubscribes from account events. 556 * @returns void 557 * @throws {BusinessError} 401 - the parameter check failed. 558 * @throws {BusinessError} 12300001 - system service exception. 559 * @throws {BusinessError} 12300002 - invalid type. 560 * @throws {BusinessError} 12300012 - the callback has not been registered. 561 * @since 9 562 */ 563 off(type: 'accountChange', callback?: Callback<Array<AppAccountInfo>>): void; 564 565 /** 566 * Authenticates an application account to get an oauth token. 567 * @param name Indicates the account name of your application or third-party applications. 568 * @param owner Indicates the account owner of your application or third-party applications. 569 * @param authType Indicates the authentication type. 570 * @param options Indicates the authenticator-specific options for the request. 571 * @param callback Indicates the authenticator callback. 572 * @returns void. 573 * @since 8 574 * @deprecated since 9 575 * @useinstead appAccount.AppAccountManager#auth 576 */ 577 authenticate(name: string, owner: string, authType: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; 578 579 /** 580 * Authenticates an application account to get an auth token. 581 * @param name Indicates the account name of your application or third-party applications. 582 * @param owner Indicates the account owner of your application or third-party applications. 583 * @param authType Indicates the authentication type. 584 * @param options Indicates the authenticator-specific options for the request. 585 * @param callback Indicates the authenticator callback. 586 * @returns void. 587 * @throws {BusinessError} 401 - the parameter check failed. 588 * @throws {BusinessError} 12300001 - system service exception. 589 * @throws {BusinessError} 12300002 - invalid name, owner, authType or options. 590 * @throws {BusinessError} 12300003 - the account indicated by owner dose not exist. 591 * @throws {BusinessError} 12300010 - account service busy. 592 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 593 * @throws {BusinessError} 12300114 - authenticator service exception. 594 * @since 9 595 */ 596 auth(name: string, owner: string, authType: string, callback: AuthCallback): void; 597 auth(name: string, owner: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void; 598 599 /** 600 * Gets an oauth token with the specified authentication type from a particular application account. 601 * @param name Indicates the account name of your application or third-party applications. 602 * @param owner Indicates the account owner of your application or third-party applications. 603 * @param authType Indicates the authentication type. 604 * @returns Returns an oauth token. 605 * @since 8 606 * @deprecated since 9 607 * @useinstead appAccount.AppAccountManager#getAuthToken 608 */ 609 getOAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void; 610 getOAuthToken(name: string, owner: string, authType: string): Promise<string>; 611 612 /** 613 * Gets an auth token with the specified authentication type from a particular application account. 614 * @param name Indicates the account name of your application or third-party applications. 615 * @param owner Indicates the account owner of your application or third-party applications. 616 * @param authType Indicates the authentication type. 617 * @returns Returns an auth token. 618 * @throws {BusinessError} 401 - the parameter check failed. 619 * @throws {BusinessError} 12300001 - system service exception. 620 * @throws {BusinessError} 12300002 - invalid name, owner or authType. 621 * @throws {BusinessError} 12300003 - the account indicated by owner dose not exist. 622 * @throws {BusinessError} 12300107 - the authType is not found. 623 * @since 9 624 */ 625 getAuthToken(name: string, owner: string, authType: string, callback: AsyncCallback<string>): void; 626 getAuthToken(name: string, owner: string, authType: string): Promise<string>; 627 628 /** 629 * Sets an oauth token with the specified authentication type for a particular account. 630 * <p> 631 * Only the owner of the application account has the permission to call this method. 632 * @param name Indicates the account name of your application. 633 * @param authType Indicates the authentication type. 634 * @param token Indicates the oauth token. 635 * @returns void. 636 * @since 8 637 * @deprecated since 9 638 * @useinstead appAccount.AppAccountManager#setAuthToken 639 */ 640 setOAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void; 641 setOAuthToken(name: string, authType: string, token: string): Promise<void>; 642 643 /** 644 * Sets an auth token with the specified authentication type for a particular account. 645 * <p> 646 * Only the owner of the application account has the permission to call this method. 647 * @param name Indicates the account name of your application. 648 * @param authType Indicates the authentication type. 649 * @param token Indicates the auth token. 650 * @returns void. 651 * @throws {BusinessError} 401 - the parameter check failed. 652 * @throws {BusinessError} 12300001 - system service exception. 653 * @throws {BusinessError} 12300002 - invalid name, owner, authType or token. 654 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 655 * @throws {BusinessError} 12400004 - the number of token has reached the upper limit. 656 * @since 9 657 */ 658 setAuthToken(name: string, authType: string, token: string, callback: AsyncCallback<void>): void; 659 setAuthToken(name: string, authType: string, token: string): Promise<void>; 660 661 /** 662 * Deletes an oauth token for the specified application account. 663 * <p> 664 * Only tokens visible to the caller application can be deleted. 665 * @param name Indicates the account name of your application or third-party applications. 666 * @param owner Indicates the account owner of your application or third-party applications. 667 * @param authType Indicates the authentication type. 668 * @param token Indicates the oauth token. 669 * @returns void. 670 * @since 8 671 * @deprecated since 9 672 * @useinstead appAccount.AppAccountManager#deleteAuthToken 673 */ 674 deleteOAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void; 675 deleteOAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>; 676 677 /** 678 * Deletes an auth token for the specified application account. 679 * <p> 680 * Only tokens visible to the caller application can be deleted. 681 * @param name Indicates the account name of your application or third-party applications. 682 * @param owner Indicates the account owner of your application or third-party applications. 683 * @param authType Indicates the authentication type. 684 * @param token Indicates the auth token. 685 * @returns void. 686 * @throws {BusinessError} 401 - the parameter check failed. 687 * @throws {BusinessError} 12300001 - system service exception. 688 * @throws {BusinessError} 12300002 - invalid name, owner, authType or token. 689 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 690 * @throws {BusinessError} 12300107 - the authType is not found. 691 * @since 9 692 */ 693 deleteAuthToken(name: string, owner: string, authType: string, token: string, callback: AsyncCallback<void>): void; 694 deleteAuthToken(name: string, owner: string, authType: string, token: string): Promise<void>; 695 696 /** 697 * Sets the oauth token visibility of the specified authentication type to a third-party application. 698 * <p> 699 * Only the owner of the application account has the permission to call this method. 700 * @param name Indicates the account name of your application. 701 * @param authType Indicates the authentication type. 702 * @param bundleName Indicates the bundle name of the third-party application. 703 * @param isVisible Indicates the bool value of visibility. 704 * @returns void. 705 * @since 8 706 * @deprecated since 9 707 * @useinstead appAccount.AppAccountManager#setAuthTokenVisibility 708 */ 709 setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void; 710 setOAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>; 711 712 /** 713 * Sets the auth token visibility of the specified authentication type to a third-party application. 714 * <p> 715 * Only the owner of the application account has the permission to call this method. 716 * @param name Indicates the account name of your application. 717 * @param authType Indicates the authentication type. 718 * @param bundleName Indicates the bundle name of the third-party application. 719 * @param isVisible Indicates the bool value of visibility. 720 * @returns void. 721 * @throws {BusinessError} 401 - the parameter check failed. 722 * @throws {BusinessError} 12300001 - system service exception. 723 * @throws {BusinessError} 12300002 - invalid name, authType or bundleName. 724 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 725 * @throws {BusinessError} 12300107 - the authType is not found. 726 * @throws {BusinessError} 12400001 - the application indicated by name does not exist. 727 * @throws {BusinessError} 12400005 - the size of authorization list reaches the upper limit. 728 * @since 9 729 */ 730 setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean, callback: AsyncCallback<void>): void; 731 setAuthTokenVisibility(name: string, authType: string, bundleName: string, isVisible: boolean): Promise<void>; 732 733 /** 734 * Checks the oauth token visibility of the specified authentication type for a third-party application. 735 * <p> 736 * Only the owner of the application account has the permission to call this method. 737 * @param name Indicates the account name of your application or third-party applications. 738 * @param authType Indicates the authentication type. 739 * @param bundleName Indicates the bundle name of the third-party application. 740 * @returns Returns the bool value of visibility. 741 * @since 8 742 * @deprecated since 9 743 * @useinstead appAccount.AppAccountManager#checkAuthTokenVisibility 744 */ 745 checkOAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void; 746 checkOAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>; 747 748 /** 749 * Checks the auth token visibility of the specified authentication type for a third-party application. 750 * <p> 751 * Only the owner of the application account has the permission to call this method. 752 * @param name Indicates the account name of your application or third-party applications. 753 * @param authType Indicates the authentication type. 754 * @param bundleName Indicates the bundle name of the third-party application. 755 * @returns Returns the bool value of visibility. 756 * @throws {BusinessError} 401 - the parameter check failed. 757 * @throws {BusinessError} 12300001 - system service exception. 758 * @throws {BusinessError} 12300002 - invalid name, authType or bundleName. 759 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 760 * @throws {BusinessError} 12300107 - the authType is not found. 761 * @since 9 762 */ 763 checkAuthTokenVisibility(name: string, authType: string, bundleName: string, callback: AsyncCallback<boolean>): void; 764 checkAuthTokenVisibility(name: string, authType: string, bundleName: string): Promise<boolean>; 765 766 /** 767 * Gets all oauth tokens visible to the caller application. 768 * @param name Indicates the account name of your application or third-party applications. 769 * @param owner Indicates the account owner of your application or third-party applications. 770 * @returns Returns a list of oauth tokens visible to the caller application. 771 * @since 8 772 * @deprecated since 9 773 * @useinstead appAccount.AppAccountManager#getAllAuthTokens 774 */ 775 getAllOAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<OAuthTokenInfo>>): void; 776 getAllOAuthTokens(name: string, owner: string): Promise<Array<OAuthTokenInfo>>; 777 778 /** 779 * Gets all auth tokens visible to the caller application. 780 * @param name Indicates the account name of your application or third-party applications. 781 * @param owner Indicates the account owner of your application or third-party applications. 782 * @returns Returns a list of auth tokens visible to the caller application. 783 * @throws {BusinessError} 401 - the parameter check failed. 784 * @throws {BusinessError} 12300001 - system service exception. 785 * @throws {BusinessError} 12300002 - invalid name or owner. 786 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 787 * @since 9 788 */ 789 getAllAuthTokens(name: string, owner: string, callback: AsyncCallback<Array<AuthTokenInfo>>): void; 790 getAllAuthTokens(name: string, owner: string): Promise<Array<AuthTokenInfo>>; 791 792 /** 793 * Gets the open authorization list with a specified authentication type for a particular application account. 794 * <p> 795 * Only the owner of the application account has the permission to call this method. 796 * @param name Indicates the account name of your application. 797 * @param authType Indicates the authentication type. 798 * @returns Returns the open authorization list of the specified authentication type. 799 * @since 8 800 * @deprecated since 9 801 * @useinstead appAccount.AppAccountManager#getAuthList 802 */ 803 getOAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void; 804 getOAuthList(name: string, authType: string): Promise<Array<string>>; 805 806 /** 807 * Gets the open authorization list with a specified authentication type for a particular application account. 808 * <p> 809 * Only the owner of the application account has the permission to call this method. 810 * @param name Indicates the account name of your application. 811 * @param authType Indicates the authentication type. 812 * @returns Returns the open authorization list of the specified authentication type. 813 * @throws {BusinessError} 401 - the parameter check failed. 814 * @throws {BusinessError} 12300001 - system service exception. 815 * @throws {BusinessError} 12300002 - invalid name or authType. 816 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 817 * @throws {BusinessError} 12300107 - the authType is not found. 818 * @since 9 819 */ 820 getAuthList(name: string, authType: string, callback: AsyncCallback<Array<string>>): void; 821 getAuthList(name: string, authType: string): Promise<Array<string>>; 822 823 /** 824 * Gets the authenticator callback with the specified session id. 825 * <p> 826 * Only the owner of the authenticator has the permission to call this method. 827 * @param sessionId Indicates the id of a authentication session. 828 * @returns Returns the authenticator callback related to the session id. 829 * @since 8 830 * @deprecated since 9 831 * @useinstead appAccount.AppAccountManager#getAuthCallback 832 */ 833 getAuthenticatorCallback(sessionId: string, callback: AsyncCallback<AuthenticatorCallback>): void; 834 getAuthenticatorCallback(sessionId: string): Promise<AuthenticatorCallback>; 835 836 /** 837 * Obtains the authenticator callback with the specified session id. 838 * <p> 839 * Only the owner of the authenticator has the permission to call this method. 840 * @param sessionId Indicates the id of a authentication session. 841 * @returns Returns the authenticator callback related to the session id. 842 * @throws {BusinessError} 401 - the parameter check failed. 843 * @throws {BusinessError} 12300001 - system service exception. 844 * @throws {BusinessError} 12300002 - invalid session id. 845 * @throws {BusinessError} 12300108 - the session indicated by sessionId does not exist. 846 * @since 9 847 */ 848 getAuthCallback(sessionId: string, callback: AsyncCallback<AuthCallback>): void; 849 getAuthCallback(sessionId: string): Promise<AuthCallback>; 850 851 /** 852 * Gets the authenticator information of an application account. 853 * @param owner Indicates the account owner of your application or third-party applications. 854 * @returns Returns the authenticator information of the application account. 855 * @since 8 856 * @deprecated since 9 857 * @useinstead appAccount.AppAccountManager#queryAuthenticatorInfo 858 */ 859 getAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void; 860 getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>; 861 862 /** 863 * Queries the authenticator information of an application account. 864 * @param owner Indicates the account owner of your application or third-party applications. 865 * @returns Returns the authenticator information of the application account. 866 * @throws {BusinessError} 401 - the parameter check failed. 867 * @throws {BusinessError} 12300001 - system service exception. 868 * @throws {BusinessError} 12300002 - invalid owner. 869 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 870 * @since 9 871 */ 872 queryAuthenticatorInfo(owner: string, callback: AsyncCallback<AuthenticatorInfo>): void; 873 queryAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo>; 874 875 /** 876 * Checks whether a particular account has all specified labels. 877 * @param name Indicates the account name. 878 * @param owner Indicates the account owner. 879 * @param labels Indicates an array of labels to check. 880 * @returns boolean 881 * @throws {BusinessError} 401 - the parameter check failed. 882 * @throws {BusinessError} 12300001 - system service exception. 883 * @throws {BusinessError} 12300002 - invalid name, owner or labels. 884 * @throws {BusinessError} 12300003 - the account indicated by owner dose not exist. 885 * @throws {BusinessError} 12300010 - account service busy. 886 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 887 * @throws {BusinessError} 12300114 - authenticator service exception. 888 * @since 9 889 */ 890 checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void; 891 checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<boolean>; 892 893 /** 894 * Deletes the credential of the specified application account. 895 * @param name Indicates the account name. 896 * @param credentialType Indicates the type of the credential to delete. 897 * @returns void. 898 * @throws {BusinessError} 401 - the parameter check failed. 899 * @throws {BusinessError} 12300001 - system service exception. 900 * @throws {BusinessError} 12300002 - invalid name or credentialType. 901 * @throws {BusinessError} 12300003 - the account indicated by name dose not exist. 902 * @throws {BusinessError} 12300102 - credential does not exist. 903 * @since 9 904 */ 905 deleteCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void; 906 deleteCredential(name: string, credentialType: string): Promise<void>; 907 908 /** 909 * Selects a list of accounts that satisfied with the specified options. 910 * @param options Indicates the options for selecting account. 911 * @returns Returns a list of accounts. 912 * @throws {BusinessError} 401 - the parameter check failed. 913 * @throws {BusinessError} 12300001 - system service exception. 914 * @throws {BusinessError} 12300002 - invalid options. 915 * @throws {BusinessError} 12300010 - account service busy. 916 * @throws {BusinessError} 12300114 - authenticator service exception. 917 * @since 9 918 */ 919 selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>): void; 920 selectAccountsByOptions(options: SelectAccountsOptions): Promise<Array<AppAccountInfo>>; 921 922 /** 923 * Verifies the credential to ensure the user is the owner of the specified account. 924 * @param name Indicates the account name. 925 * @param owner Indicates the account owner. 926 * @param options Indicates the options for verifying credential. 927 * @param callback Indicates the authenticator callback. 928 * @returns void. 929 * @throws {BusinessError} 401 - the parameter check failed. 930 * @throws {BusinessError} 12300001 - system service exception. 931 * @throws {BusinessError} 12300002 - invalid name, owner or options. 932 * @throws {BusinessError} 12300003 - the account indicated by owner dose not exist. 933 * @throws {BusinessError} 12300010 - account service busy. 934 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 935 * @throws {BusinessError} 12300114 - authenticator service exception. 936 * @since 9 937 */ 938 verifyCredential(name: string, owner: string, callback: AuthCallback): void; 939 verifyCredential(name: string, owner: string, options: VerifyCredentialOptions, callback: AuthCallback): void; 940 941 /** 942 * Sets properties for the specified account authenticator. 943 * <p> 944 * If the authenticator supports setting its properties, 945 * the caller will normally be redirected to an Ability specified by Want for property setting. 946 * @param owner Indicates the owner of authenticator. 947 * @param callback Indicates the authenticator callback. 948 * @returns void. 949 * @throws {BusinessError} 401 - the parameter check failed. 950 * @throws {BusinessError} 12300001 - system service exception. 951 * @throws {BusinessError} 12300002 - invalid owner or options. 952 * @throws {BusinessError} 12300010 - account service busy. 953 * @throws {BusinessError} 12300113 - the account authenticator service does not exist. 954 * @throws {BusinessError} 12300114 - authenticator service exception. 955 * @since 9 956 */ 957 setAuthenticatorProperties(owner: string, callback: AuthCallback): void; 958 setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthCallback): void; 959 } 960 961 /** 962 * Provides basic information of an application account, including the account owner and name. 963 * @name AppAccountInfo 964 * @syscap SystemCapability.Account.AppAccount 965 * @since 7 966 */ 967 interface AppAccountInfo { 968 /** 969 * The owner an application account. 970 */ 971 owner: string; 972 973 /** 974 * The name an application account. 975 */ 976 name: string; 977 } 978 979 /** 980 * Provides basic information of an oauth token, including the authentication type and token value. 981 * @name OAuthTokenInfo 982 * @syscap SystemCapability.Account.AppAccount 983 * @since 8 984 * @deprecated since 9 985 * @useinstead appAccount.AuthTokenInfo 986 */ 987 interface OAuthTokenInfo { 988 /** 989 * The authentication type. 990 * 991 * @since 8 992 */ 993 authType: string; 994 995 /** 996 * The token value. 997 * 998 * @since 8 999 */ 1000 token: string; 1001 } 1002 1003 /** 1004 * Provides basic information of an auth token, including the authentication type and token value. 1005 * @name AuthTokenInfo 1006 * @syscap SystemCapability.Account.AppAccount 1007 * @since 9 1008 */ 1009 interface AuthTokenInfo { 1010 /** 1011 * The authentication type. 1012 * @since 9 1013 */ 1014 authType: string; 1015 1016 /** 1017 * The token value. 1018 * @since 9 1019 */ 1020 token: string; 1021 1022 /** 1023 * The account to which the token belongs. 1024 * @since 9 1025 */ 1026 account?: AppAccountInfo; 1027 } 1028 1029 /** 1030 * Provides basic information of an authenticator, including the authenticator owner, icon id and label id. 1031 * @name AuthenticatorInfo 1032 * @syscap SystemCapability.Account.AppAccount 1033 * @since 8 1034 */ 1035 interface AuthenticatorInfo { 1036 /** 1037 * The owner of an authenticator. 1038 */ 1039 owner: string; 1040 1041 /** 1042 * The icon id of an authenticator. 1043 */ 1044 iconId: number; 1045 1046 /** 1047 * The label id of an authenticator. 1048 */ 1049 labelId: number; 1050 } 1051 1052 /** 1053 * Provides the definition of the authentication result. 1054 * @name AuthResult 1055 * @syscap SystemCapability.Account.AppAccount 1056 * @since 9 1057 */ 1058 interface AuthResult { 1059 /** 1060 * The account information. 1061 * @since 9 1062 */ 1063 account?: AppAccountInfo; 1064 1065 /** 1066 * The token information. 1067 * @since 9 1068 */ 1069 tokenInfo?: AuthTokenInfo; 1070 } 1071 1072 /** 1073 * Provides the available options for creating an account. 1074 * @name CreateAccountOptions 1075 * @syscap SystemCapability.Account.AppAccount 1076 * @since 9 1077 */ 1078 interface CreateAccountOptions { 1079 /** 1080 * The custom data for creating an account, 1081 * which can be further modified by function setCustomData. 1082 * @since 9 1083 */ 1084 customData?: {[key: string]: string}; 1085 } 1086 1087 /** 1088 * Provides the available options for creating an account implicitly. 1089 * @name CreateAccountImplicitlyOptions 1090 * @syscap SystemCapability.Account.AppAccount 1091 * 1092 * @since 9 1093 */ 1094 interface CreateAccountImplicitlyOptions { 1095 /** 1096 * The required labels for creating an account. 1097 * @since 9 1098 */ 1099 requiredLabels?: Array<string>; 1100 1101 /** 1102 * The authentication type. 1103 * @since 9 1104 */ 1105 authType?: string; 1106 1107 /** 1108 * The authenticator-specific parameters. 1109 * The list of reserved parameter name: 1110 * 1. Constants.KEY_CALLER_BUNDLE_NAME; 1111 * The above parameters are set by the appAccount management service and can be used for identify the caller. 1112 * @since 9 1113 */ 1114 parameters?: {[key:string]: Object}; 1115 } 1116 1117 /** 1118 * Provides the available options for selecting accounts. 1119 * @name SelectAccountsOptions 1120 * @syscap SystemCapability.Account.AppAccount 1121 * @since 9 1122 */ 1123 interface SelectAccountsOptions { 1124 /** 1125 * The list of accounts allowed to be selected. 1126 * @since 9 1127 */ 1128 allowedAccounts?: Array<AppAccountInfo>; 1129 1130 /** 1131 * The list of account owners, whose accounts allowed to be selected. 1132 * @since 9 1133 */ 1134 allowedOwners?: Array<string>; 1135 1136 /** 1137 * The labels required for the selected accounts. 1138 * @since 9 1139 */ 1140 requiredLabels?: Array<string>; 1141 } 1142 1143 /** 1144 * Provides the available options for verifying credential. 1145 * @name VerifyCredentialOptions 1146 * @syscap SystemCapability.Account.AppAccount 1147 * @since 9 1148 */ 1149 interface VerifyCredentialOptions { 1150 /** 1151 * The credential type to be verified. 1152 * @since 9 1153 */ 1154 credentialType?: string; 1155 1156 /** 1157 * The credential to be verified. 1158 * @since 9 1159 */ 1160 credential?: string; 1161 1162 /** 1163 * The authenticator-specific parameters. 1164 * The list of reserved parameter name: 1165 * 1. Constants.KEY_CALLER_BUNDLE_NAME; 1166 * The above parameters are set by the appAccount management service and can be used for identify the caller. 1167 * @since 9 1168 */ 1169 parameters?: {[key:string]: Object}; 1170 } 1171 1172 /** 1173 * Provides the available options for setting properties. 1174 * @name SetPropertiesOptions 1175 * @syscap SystemCapability.Account.AppAccount 1176 * @since 9 1177 */ 1178 interface SetPropertiesOptions { 1179 /** 1180 * The properties to be set. 1181 * @since 9 1182 */ 1183 properties?: {[key: string]: Object}; 1184 1185 /** 1186 * The authenticator-specific parameters. 1187 * The list of reserved parameter name: 1188 * 1. Constants.KEY_CALLER_BUNDLE_NAME; 1189 * The above parameters are set by the appAccount management service and can be used for identify the caller. 1190 * 1191 * @since 9 1192 */ 1193 parameters?: {[key: string]: Object}; 1194 } 1195 1196 /** 1197 * Provides constants definition. 1198 * @name Constants 1199 * @syscap SystemCapability.Account.AppAccount 1200 * @since 8 1201 */ 1202 enum Constants { 1203 /** 1204 * Indicates the action for adding account implicitly. 1205 * 1206 * @since 8 1207 * @deprecated since 9 1208 * @useinstead appAccount.Constants#ACTION_CREATE_ACCOUNT_IMPLICITLY 1209 */ 1210 ACTION_ADD_ACCOUNT_IMPLICITLY = "addAccountImplicitly", 1211 1212 /** 1213 * Indicates the action for authenticating. 1214 * 1215 * @since 8 1216 * @deprecated since 9 1217 * @useinstead appAccount.Constants#ACTION_AUTH 1218 */ 1219 ACTION_AUTHENTICATE = "authenticate", 1220 1221 /** 1222 * Indicates the action for creating account implicitly. 1223 * 1224 * @since 9 1225 */ 1226 ACTION_CREATE_ACCOUNT_IMPLICITLY = "createAccountImplicitly", 1227 1228 /** 1229 * Indicates the action for authenticating. 1230 * 1231 * @since 9 1232 */ 1233 ACTION_AUTH = "auth", 1234 1235 /** 1236 * Indicates the action for verifying credential. 1237 * 1238 * @since 9 1239 */ 1240 ACTION_VERIFY_CREDENTIAL = "verifyCredential", 1241 1242 /** 1243 * Indicates the action for set authenticator properties. 1244 * 1245 * @since 9 1246 */ 1247 ACTION_SET_AUTHENTICATOR_PROPERTIES = "setAuthenticatorProperties", 1248 1249 /** 1250 * Indicates the key of name. 1251 * 1252 * @since 8 1253 */ 1254 KEY_NAME = "name", 1255 1256 /** 1257 * Indicates the key of owner. 1258 * 1259 * @since 8 1260 */ 1261 KEY_OWNER = "owner", 1262 1263 /** 1264 * Indicates the key of token. 1265 * 1266 * @since 8 1267 */ 1268 KEY_TOKEN = "token", 1269 1270 /** 1271 * Indicates the key of action. 1272 * 1273 * @since 8 1274 */ 1275 KEY_ACTION = "action", 1276 1277 /** 1278 * Indicates the key of authentication type. 1279 * 1280 * @since 8 1281 */ 1282 KEY_AUTH_TYPE = "authType", 1283 1284 /** 1285 * Indicates the key of session id. 1286 * 1287 * @since 8 1288 */ 1289 KEY_SESSION_ID = "sessionId", 1290 1291 /** 1292 * Indicates the key of caller pid. 1293 * 1294 * @since 8 1295 */ 1296 KEY_CALLER_PID = "callerPid", 1297 1298 /** 1299 * Indicates the key of caller uid. 1300 * 1301 * @since 8 1302 */ 1303 KEY_CALLER_UID = "callerUid", 1304 1305 /** 1306 * Indicates the key of caller bundle name. 1307 * 1308 * @since 8 1309 */ 1310 KEY_CALLER_BUNDLE_NAME = "callerBundleName", 1311 1312 /** 1313 * Indicates the key of required labels. 1314 * 1315 * @since 9 1316 */ 1317 KEY_REQUIRED_LABELS = "requiredLabels", 1318 1319 /** 1320 * Indicates the key of boolean result. 1321 * 1322 * @since 9 1323 */ 1324 KEY_BOOLEAN_RESULT = "booleanResult" 1325 } 1326 1327 /** 1328 * Provides result code definition. 1329 * @name ResultCode 1330 * @syscap SystemCapability.Account.AppAccount 1331 * @since 8 1332 * @deprecated since 9 1333 */ 1334 enum ResultCode { 1335 SUCCESS = 0, 1336 ERROR_ACCOUNT_NOT_EXIST = 10001, 1337 ERROR_APP_ACCOUNT_SERVICE_EXCEPTION = 10002, 1338 ERROR_INVALID_PASSWORD = 10003, 1339 ERROR_INVALID_REQUEST = 10004, 1340 ERROR_INVALID_RESPONSE = 10005, 1341 ERROR_NETWORK_EXCEPTION = 10006, 1342 ERROR_OAUTH_AUTHENTICATOR_NOT_EXIST = 10007, 1343 ERROR_OAUTH_CANCELED = 10008, 1344 ERROR_OAUTH_LIST_TOO_LARGE = 10009, 1345 ERROR_OAUTH_SERVICE_BUSY = 10010, 1346 ERROR_OAUTH_SERVICE_EXCEPTION = 10011, 1347 ERROR_OAUTH_SESSION_NOT_EXIST = 10012, 1348 ERROR_OAUTH_TIMEOUT = 10013, 1349 ERROR_OAUTH_TOKEN_NOT_EXIST = 10014, 1350 ERROR_OAUTH_TOKEN_TOO_MANY = 10015, 1351 ERROR_OAUTH_UNSUPPORT_ACTION = 10016, 1352 ERROR_OAUTH_UNSUPPORT_AUTH_TYPE = 10017, 1353 ERROR_PERMISSION_DENIED = 10018 1354 } 1355 1356 /** 1357 * Provides methods for authenticator callback. 1358 * @name AuthenticatorCallback 1359 * @syscap SystemCapability.Account.AppAccount 1360 * @since 8 1361 * @deprecated since 9 1362 * @useinstead AppAccount.AuthCallback 1363 * 1364 */ 1365 interface AuthenticatorCallback { 1366 /** 1367 * Notifies the client of the authentication result. 1368 * @param code Indicates the result code. 1369 * @param result Indicates the authentication result. 1370 * @returns void. 1371 * @since 8 1372 */ 1373 onResult: (code: number, result: {[key: string]: any}) => void; 1374 1375 /** 1376 * Notifies the client that the authentication request need to be redirected. 1377 * @param request Indicates the request information to be redirected. 1378 * @returns void. 1379 * @since 8 1380 */ 1381 onRequestRedirected: (request: Want) => void; 1382 } 1383 1384 /** 1385 * Provides methods for authentication callback. 1386 * @name AuthCallback 1387 * @syscap SystemCapability.Account.AppAccount 1388 * @since 9 1389 */ 1390 interface AuthCallback { 1391 /** 1392 * Notifies the client of the authentication result. 1393 * @param code Indicates the result code. 1394 * @param result Indicates the authentication result. 1395 * @returns void. 1396 * @since 9 1397 */ 1398 onResult: (code: number, result?: AuthResult) => void; 1399 1400 /** 1401 * Notifies the client that the authentication request need to be redirected. 1402 * @param request Indicates the request information to be redirected. 1403 * @returns void. 1404 * @since 9 1405 */ 1406 onRequestRedirected: (request: Want) => void; 1407 1408 /** 1409 * Notifies the client that the request is continued. 1410 * @returns void. 1411 * @since 9 1412 */ 1413 onRequestContinued?: () => void; 1414 } 1415 1416 /** 1417 * Provides methods for authenticator. 1418 * @name Authenticator 1419 * @syscap SystemCapability.Account.AppAccount 1420 * @since 8 1421 */ 1422 class Authenticator { 1423 /** 1424 * Adds an application account of a specified owner implicitly. 1425 * @param authType Indicates the authentication type. 1426 * @param callerBundleName Indicates the caller bundle name. 1427 * @param options Indicates the authenticator-specific options for the request. 1428 * @param callback Indicates the authenticator callback. 1429 * @returns void. 1430 * @since 8 1431 * @deprecated since 9 1432 * @useinstead appAccount.Authenticator#createAccountImplicitly 1433 */ 1434 addAccountImplicitly(authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; 1435 1436 /** 1437 * Creates an application account of a specified owner implicitly. 1438 * @param options Indicates the authenticator-specific options for the request. 1439 * @param callback Indicates the authenticator callback. 1440 * @returns void. 1441 * @since 9 1442 */ 1443 createAccountImplicitly(options: CreateAccountImplicitlyOptions, callback: AuthCallback): void; 1444 1445 /** 1446 * Authenticates an application account to get an oauth token. 1447 * @param name Indicates the account name. 1448 * @param authType Indicates the authentication type. 1449 * @param callerBundleName Indicates the caller bundle name. 1450 * @param options Indicates the authenticator-specific options for the request. 1451 * @param callback Indicates the authenticator callback. 1452 * @returns void. 1453 * @since 8 1454 * @deprecated since 9 1455 * @useinstead appAccount.Authenticator#auth 1456 */ 1457 authenticate(name: string, authType: string, callerBundleName: string, options: {[key: string]: any}, callback: AuthenticatorCallback): void; 1458 1459 /** 1460 * Authenticates an application account to get an oauth token. 1461 * @param name Indicates the account name. 1462 * @param authType Indicates the authentication type. 1463 * @param options Indicates the authenticator-specific options for the request. 1464 * @param callback Indicates the authenticator callback. 1465 * @returns void. 1466 * @since 9 1467 */ 1468 auth(name: string, authType: string, options: {[key:string]: Object}, callback: AuthCallback): void; 1469 1470 /** 1471 * Verifies the credential to ensure the user is the owner of the specified application account. 1472 * <p> 1473 * The credential can be provided in the options, otherwise an Ability will normally be returned, 1474 * which can be started by the caller to further verify credential. 1475 * @param name Indicates the name of the application account. 1476 * @param options Indicates the options for verifying credential. 1477 * @param callback Indicates the authenticator callback. 1478 * @returns void. 1479 * @since 9 1480 */ 1481 verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthCallback): void; 1482 1483 /** 1484 * Sets properties for the authenticator. 1485 * @param options Indicates the options for setting properties. 1486 * @param callback Indicates the authenticator callback. 1487 * @returns void. 1488 * @since 9 1489 */ 1490 setProperties(options: SetPropertiesOptions, callback: AuthCallback): void; 1491 1492 /** 1493 * Checks whether a particular account has all specified labels. 1494 * @param name Indicates the account name. 1495 * @param labels Indicates an array of labels to check. 1496 * @param callback Indicates the authenticator callback. 1497 * @returns void. 1498 * @since 9 1499 */ 1500 checkAccountLabels(name: string, labels: Array<string>, callback: AuthCallback): void; 1501 1502 /** 1503 * Checks whether the specified account can be removed. 1504 * @param name Indicates the account name. 1505 * @param callback Indicates the authenticator callback. 1506 * @returns void. 1507 * @since 9 1508 */ 1509 checkAccountRemovable(name: string, callback: AuthCallback): void; 1510 1511 /** 1512 * Gets the remote object of the authenticator for remote procedure call. 1513 * @returns Returns a remote object. 1514 * @since 9 1515 */ 1516 getRemoteObject(): rpc.RemoteObject; 1517 } 1518} 1519 1520export default appAccount;