diff --git a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md index b229c5eeb838f1fe3bf21d58ae8b0caf9f2b6796..65267a4217ecb7192bc771f5e6f9bde9a2648e4a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-appAccount.md +++ b/zh-cn/application-dev/reference/apis/js-apis-appAccount.md @@ -1565,6 +1565,376 @@ getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> }); ``` +### checkAppAccess9+ + +checkAppAccess(name: string, bundleName: string, callback: AsyncCallback<boolean>): void + +检查指定应用帐户对特定应用是否授权,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ---------------------------- | ----- | ---------------- | +| name | string | 是 | 应用帐户的名称。 | +| bundleName | string | 是 | 被检查的应用包名。 | +| callback | AsyncCallback<boolean> | 是 | 检查结果的回调。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => { + console.log('checkAppAccess: ' + JSON.stringify(data)); + console.log("checkAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### checkAppAccess9+ + +checkAppAccess(name: string, bundleName: string): Promise<boolean> + +检查指定应用帐户对特定应用是否授权,使用Promise方式异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ------ | ----- | ---------------- | +| name | string | 是 | 应用帐户的名称。 | +| bundleName | string | 是 | 被检查的应用包名。 | + +**参数:** + +| 类型 | 说明 | +| ---------------------- | --------------------------------- | +| Promise<boolean> | Promise实例,用于获取异步返回结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAppAccess("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { + console.log('checkAppAccess: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("checkAppAccess err: " + JSON.stringify(err)); + }); + ``` + +### deleteAccountCredential9+ + +deleteAccountCredential(name: string, credentialType: string, callback: AsyncCallback<void>): void + +删除指定应用帐户的指定类型的凭据信息,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ------------------------- | ----- | -------------- | +| name | string | 是 | 应用帐户的名称。 | +| credentialType | string | 是 | 凭据类型。 | +| callback | AsyncCallback<void> | 是 | 删除结果的回调。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccountCredential("zhangsan", "pin", (err, data) => { + console.log('deleteAccountCredential: ' + JSON.stringify(data)); + console.log("deleteAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### deleteAccountCredential9+ + +deleteAccountCredential(name: string, credentialType: string): Promise<void> + +删除指定应用帐户的指定类型的凭据信息,使用Promise方式异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ------ | ----- | --------------- | +| name | string | 是 | 应用帐户的名称。 | +| credentialType | string | 是 | 凭据类型。 | + +**参数:** + +| 类型 | 说明 | +| ------------------- | -------------------------------- | +| Promise<void> | Promise实例,用于获取异步返回结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.deleteAccountCredential("zhangsan", "pin").then((data) => { + console.log('deleteAccountCredential: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("deleteAccountCredential err: " + JSON.stringify(err)); + }); + ``` + +### checkAccountLabels9+ + +checkAccountLabels(name: string, owner: string, labels: Array<string>, callback: AsyncCallback<boolean>): void; + +检查指定帐户是否具有特定的标签集合,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ------------------------- | ----- | --------------- | +| name | string | 是 | 应用帐户的名称。 | +| owner | string | 是 | 应用帐户的所有者。| +| labels | Array<string< | 是 | 标签数组。 | +| callback | AsyncCallback<void> | 是 | 检查结果的回调。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo", (err, data) => { + console.log('checkAccountLabels: ' + JSON.stringify(data)); + console.log("checkAccountLabels err: " + JSON.stringify(err)); + }); + ``` + +### checkAccountLabels9+ + +checkAccountLabels(name: string, owner: string, labels: Array<string>): Promise<void> + +检查指定帐户是否具有特定的标签集合,使用Promise方式异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ------------------------- | ----- | --------------- | +| name | string | 是 | 应用帐户的名称。 | +| owner | string | 是 | 应用帐户的所有者。| +| labels | Array<string< | 是 | 标签数组。 | + +**参数:** + +| 类型 | 说明 | +| ------------------- | -------------------------------- | +| Promise<boolean> | Promise实例,用于获取异步返回结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.checkAccountLabels("zhangsan", "com.example.ohos.accountjsdemo").then((data) => { + console.log('checkAccountLabels: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("checkAccountLabels err: " + JSON.stringify(err)); + }); + ``` + +### selectAccountsByOptions9+ + +selectAccountsByOptions(options: SelectAccountsOptions, callback: AsyncCallback<Array<AppAccountInfo>>); + +根据选项选择请求方可访问的帐号列表,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ----------------------------------- | ----- | --------------- | +| options | SelectAccountsOptions | 是 | 选择帐户的选项。 | +| callback | AsyncCallback<AppAccountInfo> | 是 | 选择结果的回调。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + var options = { + allowedOwners: ["com.example.ohos.accountjsdemo"] + }; + appAccountManager.selectAccountsByOptions(options, (err, data) => { + console.log('selectAccountsByOptions: ' + JSON.stringify(data)); + console.log("selectAccountsByOptions err: " + JSON.stringify(err)); + }); + ``` + +### selectAccountsByOptions9+ + +selectAccountsByOptions(options: SelectAccountsOptions): Promise<void> + +根据选项选择请求方可访问的帐户列表,使用Promise方式异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ------------------------- | ----- | --------------- | +| options | SelectAccountsOptions | 是 | 选择帐户的选项。 | + +**参数:** + +| 类型 | 说明 | +| ------------------- | -------------------------------- | +| Promise<AppAccountInfo> | Promise实例,用于获取异步返回结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + var options = { + allowedOwners: ["com.example.ohos.accountjsdemo"] + }; + appAccountManager.selectAccountsByOptions(options).then((data) => { + console.log('selectAccountsByOptions: ' + JSON.stringify(data)); + }).catch((err) => { + console.log("selectAccountsByOptions err: " + JSON.stringify(err)); + }); + ``` + +### verifyCredential9+ + +verifyCredential(name: string, owner: string, callback: AuthenticatorCallback): void; + +验证用户凭据,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ----- | ----------------------- | +| name | string | 是 | 应用帐户的名称。 | +| owner | string | 是 | 应用帐户的所有者。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,返回验证结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", { + onResult: (resultCode, result) => { + console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("verifyCredential onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + ``` + +### verifyCredential9+ + +verifyCredential(name: string, owner: string, options, callback: AuthenticatorCallback): void; + +验证用户凭据,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ----- | ----------------------- | +| name | string | 是 | 应用帐户的名称。 | +| owner | string | 是 | 应用帐户的所有者。 | +| options | VerifyCredentialOptions | 是 | 验证凭据的选项。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,返回验证结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + var options = { + credentialType: "pin", + credential: "123456" + }; + appAccountManager.verifyCredential("zhangsan", "com.example.ohos.accountjsdemo", options, { + onResult: (resultCode, result) => { + console.log("verifyCredential onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("verifyCredential onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("verifyCredential onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + ``` + +### setAuthenticatorProperties9+ + +setAuthenticatorProperties(owner: string, callback: AuthenticatorCallback): void; + +设置认证器属性,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ----- | ----------------------- | +| owner | string | 是 | 认证器的所有者。 | +| options | SetPropertiesOptions | 是 | 设置属性的选项。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,返回设置结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", { + onResult: (resultCode, result) => { + console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + ``` + +### setAuthenticatorProperties9+ + +setAuthenticatorProperties(owner: string, options: SetPropertiesOptions, callback: AuthenticatorCallback): void; + +设置认证器属性,使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ----- | ----------------------- | +| owner | string | 是 | 认证器的所有者。 | +| options | SetPropertiesOptions | 是 | 设置属性的选项。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,返回设置结果。 | + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + var options = { + properties: {"prop1": "value1"} + }; + appAccountManager.setAuthenticatorProperties("com.example.ohos.accountjsdemo", options, { + onResult: (resultCode, result) => { + console.log("setAuthenticatorProperties onResult, resultCode:" + JSON.stringify(resultCode)); + console.log("setAuthenticatorProperties onResult, result:" + JSON.stringify(result)); + }, + onRequestRedirected: (request) => { + console.log("setAuthenticatorProperties onRequestRedirected, request:" + JSON.stringify(request)); + } + }); + ``` + ## AppAccountInfo 表示应用帐号信息。 @@ -1599,6 +1969,42 @@ getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> | iconId | string | 是 | 认证器的图标标识。 | | labelId | string | 是 | 认证器的标签标识。 | +## SelectAccountsOptions9+ + +表示用于选择帐号的选项。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | --------------------------- | ----- | ------------------- | +| allowedAccounts | Array<AppAccountInfo> | 否 | 允许的帐号数组。 | +| allowedOwners | Array<string> | 否 | 允许的帐号所有者数组。 | +| requiredLabels | Array<string> | 否 | 认证器的标签标识。 | + +## VerifyCredentialOptions9+ + +表示用于验证凭据的选项。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 + +| 参数名 | 类型 | 必填 | 说明 | +| -------------- | ---------------------- | ----- | -------------- | +| credentialType | string | 否 | 凭据类型。 | +| credential | string | 否 | 凭据取值。 | +| parameters | {[key:string]: Object} | 否 | 自定义参数对象。 | + + +## SetPropertiesOptions9+ + +表示用于设置属性的选项。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Account.AppAccount。 + +| 参数名 | 类型 | 必填 | 说明 | +| ---------- | ---------------------- | ----- | -------------- | +| properties | {[key:string]: Object} | 否 | 属性对象。 | +| parameters | {[key:string]: Object} | 否 | 自定义参数对象。 | + ## Constants8+ 表示常量的枚举。 @@ -1618,6 +2024,8 @@ getAuthenticatorInfo(owner: string): Promise<AuthenticatorInfo> | KEY_CALLER_PID | "callerPid" | 表示键名,调用方PID。 | | KEY_CALLER_UID | "callerUid" | 表示键名,调用方UID。 | | KEY_CALLER_BUNDLE_NAME | "callerBundleName" | 表示键名,调用方包名。 | +| KEY_REQUIRED_LABELS | "requiredLabels" | 表示键名,必需的标签。 | +| KEY_BOOLEAN_RESULT | "booleanResult" | 表示键名,布尔返回值。 | ## ResultCode8+ @@ -1655,7 +2063,7 @@ OAuth认证器回调接口。 onResult: (code: number, result: {[key: string]: any}) => void -通知鉴权结果。 +通知请求结果。 **系统能力:** SystemCapability.Account.AppAccount @@ -1685,7 +2093,7 @@ onResult: (code: number, result: {[key: string]: any}) => void onRequestRedirected: (request: Want) => void -通知鉴权请求被跳转。 +通知请求被跳转。 **系统能力:** SystemCapability.Account.AppAccount @@ -1714,9 +2122,29 @@ onRequestRedirected: (request: Want) => void } ``` +### onRequestContinued9+ + +onRequestContinued: () => void + +通知请求被继续处理。 + +**系统能力:** SystemCapability.Account.AppAccount + +**示例:** + + ```js + const appAccountManager = account_appAccount.createAppAccountManager(); + var sessionId = "1234"; + appAccountManager.getAuthenticatorCallback(sessionId).then((callback) => { + callback.OnRequestContinued(); + }).catch((err) => { + console.log("getAuthenticatorCallback err: " + JSON.stringify(err)); + }); + ``` + ## Authenticator8+ -OAuth认证器基类。 +认证器基类。 ### addAccountImplicitly8+ @@ -1751,6 +2179,72 @@ authenticate(name: string, authType: string, callerBundleName: string, options: | options | {[key: string]: any} | 是 | 鉴权所需要的可选项。 | | callback | AuthenticatorCallback | 是 | 认证器回调,用于返回鉴权结果。 | +### verifyCredential9+ + +verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback): void; + +验证应用帐户的凭据,并使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** +| 接口名 | 类型 | 必填 | 说明 | +| --------- | ------------------------ | -- -- | --------------------------- | +| name | string | 是 | 应用帐号的名称。 | +| options | VerifyCredentialOptions | 是 | 验证凭据的可选项。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,用于返回验证结果。 | + +### setProperties9+ + +setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback): void; + +设置认证器属性,并使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** +| 接口名 | 类型 | 必填 | 说明 | +| --------- | --------------------- | -- -- | --------------------------- | +| options | SetPropertiesOptions | 是 | 设置属性的可选项。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,用于返回设置结果。 | + +### checkAccountLabels9+ + +checkAccountLabels(name: string, labels: Array<string>, callback: AuthenticatorCallback): void; + +检查帐号标签,并使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** +| 接口名 | 类型 | 必填 | 说明 | +| --------- | --------------------- | -- -- | --------------------------- | +| name | string | 是 | 应用帐号的名称。 | +| labels | Array | 是 | 标签数组。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,用于返回检查结果。 | + +### isAccountRemovable9+ + +isAccountRemovable(name: string, callback: AuthenticatorCallback): void; + +判断帐号是否可以删除,并使用callback回调异步返回结果。 + +**系统能力:** SystemCapability.Account.AppAccount + +**参数:** +| 接口名 | 类型 | 必填 | 说明 | +| --------- | --------------------- | -- -- | --------------------------- | +| name | string | 是 | 应用帐号的名称。 | +| callback | AuthenticatorCallback | 是 | 认证器回调,用于返回判断结果。 | + +### getRemoteObject9+ + +getRemoteObject(): rpc.RemoteObject; + +获取认证器的远程对象,不可以重载实现。 + +**系统能力:** SystemCapability.Account.AppAccount + **示例:** ```js @@ -1768,6 +2262,30 @@ authenticate(name: string, authType: string, callerBundleName: string, options: [account_appAccount.Constants.KEY_TOKEN]: "xxxxxx"}; callback.onResult(account_appAccount.ResultCode.SUCCESS, result); } + + verifyCredential(name: string, options: VerifyCredentialOptions, callback: AuthenticatorCallback) { + callback.onRequestRedirected({ + bundleName: "com.example.ohos.accountjsdemo", + abilityName: "com.example.ohos.accountjsdemo.VerifyAbility", + parameters: { + name: name + } + }); + } + + setProperties(options: SetPropertiesOptions, callback: AuthenticatorCallback) { + callback.onResult(account_appAccount.ResultCode.SUCCESS, {}); + } + + checkAccountLabels(name: string, labels: Array<string>, callback: AuthenticatorCallback) { + var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: false}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } + + isAccountRemovable(name, callback) { + var result = {[account_appAccount.Constants.KEY_BOOLEAN_RESULT]: true}; + callback.onResult(account_appAccount.ResultCode.SUCCESS, result); + } } export default {