From 8c1074004686256108198eb06830b1694f3b988e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=96=8C?= Date: Mon, 6 Mar 2023 09:34:33 +0000 Subject: [PATCH] update zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 徐斌 --- .../arkui-ts/ts-basic-components-web.md | 115 +++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md index 7059d1f5eb..5e6e0bdf48 100755 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md @@ -2259,7 +2259,7 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH **示例:** ```ts - // xxx.ets + // xxx.ets API9 import web_webview from '@ohos.web.webview' @Entry @Component @@ -2296,6 +2296,107 @@ onClientAuthenticationRequest(callback: (event: {handler : ClientAuthenticationH } ``` + **示例:** + ```ts + // xxx.ets API10 + import web_webview from '@ohos.web.webview' + import bundle from '@ohos.bundle' + + let uri = ""; + + export default class CertManagerService { + private static sInstance: CertManagerService; + private authUri = ""; + + public static getInstance(): CertManagerService { + if (CertManagerService.sInstance == null) { + CertManagerService.sInstance = new CertManagerService(); + } + return CertManagerService.sInstance; + } + + async grantAppPm(callback) { + let message = ''; + //注:com.example.myapplication需要写实际应用名称 + let bundleInfo = await bundle.getBundleInfo("com.example.myapplication", bundle.BundleFlag.GET_BUNDLE_DEFAULT) + let clientAppUid = bundleInfo.uid + let appUid = clientAppUid.toString() + + //注:globalThis.AbilityContext需要在MainAbility.ts文件的onCreate函数里添加globalThis.AbilityContext = this.context + await globalThis.AbilityContext.startAbilityForResult( + { + bundleName: "com.ohos.certmanager", + abilityName: "MainAbility", + uri: "requestAuthorize", + parameters: { + appUid: appUid, //传入申请应用的appUid + } + }) + .then((data) => { + if (!data.resultCode) { + this.authUri = data.want.parameters.authUri; //授权成功后获取返回的authUri + } + }) + message += "after grantAppPm authUri: " + this.authUri; + uri = this.authUri; + callback(message) + } + } + + @Entry + @Component + struct WebComponent { + controller: web_webview.WebviewController = new web_webview.WebviewController(); + @State message: string = 'Hello World' //message主要是调试观察使用 + certManager = CertManagerService.getInstance(); + + build() { + Row() { + Column() { + Row() { + //第一步:需要先进行授权,获取到uri + Button('GrantApp') + .onClick(() => { + this.certManager.grantAppPm((data) => { + this.message = data; + }); + }) + //第二步:授权后,双向认证会通过onClientAuthenticationRequest回调将uri传给web进行认证 + Button("ClientCertAuth") + .onClick(() => { + this.controller.loadUrl('https://www.example2.com'); //支持双向认证的服务器网站 + }) + } + + Web({ src: 'https://www.example1.com', controller: this.controller }) + .fileAccess(true) + .javaScriptAccess(true) + .domStorageAccess(true) + .onlineImageAccess(true) + + .onClientAuthenticationRequest((event) => { + AlertDialog.show({ + title: 'ClientAuth', + message: 'Text', + confirm: { + value: 'Confirm', + action: () => { + event.handler.confirm(uri); + } + }, + cancel: () => { + event.handler.cancel(); + } + }) + }) + } + } + .width('100%') + .height('100%') + } + } + ``` + ### onPermissionRequest9+ onPermissionRequest(callback: (event?: { request: PermissionRequest }) => void) @@ -3405,6 +3506,18 @@ confirm(priKeyFile : string, certChainFile : string): void | priKeyFile | string | 是 | 存放私钥的文件,包含路径和文件名。 | | certChainFile | string | 是 | 存放证书链的文件,包含路径和文件名。 | +### confirm10+ + +confirm(authUri : string): void + +通知Web组件使用指定的凭据(从证书管理模块获得)。 + +**参数:** + +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ------- | ------ | ---- | ------------- | +| authUri | string | 是 | 凭据的关键值。 | + ### cancel9+ cancel(): void -- GitLab