diff --git a/zh-cn/application-dev/security/userauth-guidelines-API6.md b/zh-cn/application-dev/security/userauth-guidelines-api6.md similarity index 90% rename from zh-cn/application-dev/security/userauth-guidelines-API6.md rename to zh-cn/application-dev/security/userauth-guidelines-api6.md index bfb2859b4daa0962b1806157d7a29f64fbdc7e2e..671a7207d3cb8280b2dcd2bc550c1be903fcb8a9 100644 --- a/zh-cn/application-dev/security/userauth-guidelines-API6.md +++ b/zh-cn/application-dev/security/userauth-guidelines-api6.md @@ -1,11 +1,11 @@ # 用户认证开发指导 +> **说明:**该开发指导匹配@ohos.userIAM.userAuth API Version 6开始支持的接口。对应接口已在API Version 8废弃,建议使用{新接口](#userauth-guidelines-api8.md)。 + ## 场景介绍 当前用户认证支持2D人脸识别、3D人脸识别,可应用于设备解锁、应用登录、支付等身份认证场景。 -此文档适用于用户认证API6接口的开发指导。 - ## 接口说明 userIAM_userAuth模块提供了用户认证的相关方法,包括获取认证对象、认证,用户可以使用人脸等生物特征信息进行认证操作。具体接口说明可以查阅[API参考](../reference/apis/js-apis-useriam-userauth.md)。 diff --git a/zh-cn/application-dev/security/userauth-guidelines-API8.md b/zh-cn/application-dev/security/userauth-guidelines-api8.md similarity index 52% rename from zh-cn/application-dev/security/userauth-guidelines-API8.md rename to zh-cn/application-dev/security/userauth-guidelines-api8.md index 1267bf8780a1bf76c1fcde57298e36353c9fd65d..43768f5fe707ae9ebccc6417f84a0638140c0da1 100644 --- a/zh-cn/application-dev/security/userauth-guidelines-API8.md +++ b/zh-cn/application-dev/security/userauth-guidelines-api8.md @@ -1,11 +1,11 @@ # 用户认证开发指导 +> **说明:**该开发指导匹配@ohos.userIAM.userAuth API Version 8开始支持的接口。 + ## 场景介绍 当前用户认证支持2D人脸识别、3D人脸识别,可应用于设备解锁、应用登录、支付等身份认证场景。 -此文档适用于用户认证API8接口的开发指导。 - ## 接口说明 userIAM_userAuth模块提供了用户认证的相关方法,包括检测认证能力、认证和取消认证等,用户可以使用人脸等生物特征信息进行认证操作。具体接口说明可以查阅[API参考](../reference/apis/js-apis-useriam-userauth.md)。 @@ -39,67 +39,67 @@ userIAM_userAuth模块提供了用户认证的相关方法,包括检测认证 2. (可选)获取认证器的版本信息,代码示例如下: ```js - let auth = new userIAM_userAuth.UserAuth(); - let version = auth.getVersion(); - console.info("auth version = " + version); + let auth = new userIAM_userAuth.UserAuth(); + let version = auth.getVersion(); + console.info("auth version = " + version); ``` - + 3. 根据指定的认证类型、认证等级,检测当前设备是否支持相应的认证能力,代码示例如下: ```js - let auth = new userIAM_userAuth.UserAuth(); - let checkCode = auth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1); - if (checkCode == userIAM_userAuth.ResultCode.SUCCESS) { - console.info("check auth support success"); - // 此处添加支持指定类型认证的逻辑 - } else { - console.error("check auth support fail, code = " + checkCode); - // 此处添加不支持指定类型认证的逻辑 - } + let auth = new userIAM_userAuth.UserAuth(); + let checkCode = auth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1); + if (checkCode == userIAM_userAuth.ResultCode.SUCCESS) { + console.info("check auth support success"); + // 此处添加支持指定类型认证的逻辑 + } else { + console.error("check auth support fail, code = " + checkCode); + // 此处添加不支持指定类型认证的逻辑 + } ``` 4. 执行认证操作,代码示例如下: ```js - let auth = new userIAM_userAuth.UserAuth(); - auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, { - onResult: (result, extraInfo) => { - try { - console.info("auth onResult result = " + result); - console.info("auth onResult extraInfo = " + JSON.stringify(extraInfo)); - if (result == 'SUCCESS') { - // 此处添加认证成功逻辑 - } else { - // 此处添加认证失败逻辑 - } - } catch (e) { - console.info("auth onResult error = " + e); - } - }, - - onAcquireInfo: (module, acquire, extraInfo) => { - try { - console.info("auth onAcquireInfo module = " + module); - console.info("auth onAcquireInfo acquire = " + acquire); - console.info("auth onAcquireInfo extraInfo = " + JSON.stringify(extraInfo)); - } catch (e) { - console.info("auth onAcquireInfo error = " + e); - } - } - }); + let auth = new userIAM_userAuth.UserAuth(); + auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, { + onResult: (result, extraInfo) => { + try { + console.info("auth onResult result = " + result); + console.info("auth onResult extraInfo = " + JSON.stringify(extraInfo)); + if (result == 'SUCCESS') { + // 此处添加认证成功逻辑 + } else { + // 此处添加认证失败逻辑 + } + } catch (e) { + console.info("auth onResult error = " + e); + } + }, + + onAcquireInfo: (module, acquire, extraInfo) => { + try { + console.info("auth onAcquireInfo module = " + module); + console.info("auth onAcquireInfo acquire = " + acquire); + console.info("auth onAcquireInfo extraInfo = " + JSON.stringify(extraInfo)); + } catch (e) { + console.info("auth onAcquireInfo error = " + e); + } + } + }); ``` 5. 认证过程中取消认证,代码示例如下: ```js - // contextId可通过auth接口获取,此处直接定义 - let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); - let cancelCode = auth.cancel(contextId); - if (cancelCode == userIAM_userAuth.ResultCode.SUCCESS) { - console.info("cancel auth success"); - } else { - console.error("cancel auth fail"); - } + // contextId可通过auth接口获取,此处直接定义 + let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); + let cancelCode = auth.cancel(contextId); + if (cancelCode == userIAM_userAuth.ResultCode.SUCCESS) { + console.info("cancel auth success"); + } else { + console.error("cancel auth fail"); + } ```