js-apis-useriam-userauth.md 35.9 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.userIAM.userAuth (用户认证)
Z
zengyawen 已提交
2

3 4 5
提供用户认证能力,可应用于设备解锁、支付、应用登录等身份认证场景。

> **说明:**
Z
zengyawen 已提交
6 7 8 9 10
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。


## 导入模块

11
```js
Z
zengyawen 已提交
12 13 14
import userIAM_userAuth from '@ohos.userIAM.userAuth';
```

Y
youliang_1314 已提交
15 16 17 18 19 20
## AuthResultInfo<sup>9+</sup>

表示认证结果信息。

**系统能力**:以下各项对应的系统能力均为SystemCapability.UserIAM.UserAuth.Core。

Y
youliang_1314 已提交
21
| 名称         | 类型   | 必填 | 说明                 |
Y
youliang_1314 已提交
22 23 24 25 26 27 28 29 30 31 32 33
| ------------ | ---------- | ---- | -------------------- |
| result        | number | 是   | 认证结果。       |
| token        | Uint8Array | 否   | 用户身份认证通过的凭证。 |
| remainAttempts  | number     | 否   | 剩余的认证操作次数。 |
| lockoutDuration | number     | 否   | 认证操作的冻结时间。 |

## TipInfo<sup>9+</sup>

表示认证过程中的提示信息。

**系统能力**:以下各项对应的系统能力均为SystemCapability.UserIAM.UserAuth.Core。

Y
youliang_1314 已提交
34
| 名称         | 类型   | 必填 | 说明                 |
Y
youliang_1314 已提交
35 36 37 38
| ------------ | ---------- | ---- | -------------------- |
| module        | number | 是   | 发送提示信息的模块标识。       |
| tip        | number | 是   | 认证过程提示信息。       |

Y
youliang_1314 已提交
39 40
## EventInfo<sup>9+</sup>

Y
youliang_1314 已提交
41
表示认证过程中事件信息的类型。
Y
youliang_1314 已提交
42

Y
youliang_1314 已提交
43
**系统能力**:以下各项对应的系统能力均为SystemCapability.UserIAM.UserAuth.Core。
Y
youliang_1314 已提交
44

Y
youliang_1314 已提交
45
| 取值类型    | 说明                       |
Y
youliang_1314 已提交
46
| --------- | ----------------------- |
47 48
| [AuthResultInfo](#authresultinfo9)    | 获取到的认证结果信息。  |
| [TipInfo](#tipinfo9)    | 认证过程中的提示信息。      |
Y
youliang_1314 已提交
49

Y
youliang_1314 已提交
50 51 52 53 54 55 56 57 58
## AuthEventKey<sup>9+</sup>

表示认证事件类型的关键字,作为[on](#on9)接口的的参数。

| 取值类型       | 说明                    |
| ---------- | ----------------------- |
| "result" | [on](#on9)接口第一个参数为"result"时,[callback](#callback9)回调返回认证的结果信息。 |
| "tip"    | [on](#on9)接口第一个参数为"tip"时,[callback](#callback9)回调返回认证操作中的提示信息。 |

Y
youliang_1314 已提交
59 60
## AuthEvent<sup>9+</sup>

Y
youliang_1314 已提交
61
认证接口的异步回调对象。
Y
youliang_1314 已提交
62 63 64

### callback<sup>9+</sup>

Y
youliang_1314 已提交
65
callback(result : EventInfo) : void
Y
youliang_1314 已提交
66

Y
youliang_1314 已提交
67
通过该回调获取认证结果信息或认证过程中的提示信息。
Y
youliang_1314 已提交
68 69 70 71 72

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**

Y
youliang_1314 已提交
73
| 参数名    | 类型                       | 必填 | 说明                           |
74 75
| --------- | -------------------------- | ---- | ------------------------------ |
| result    | [EventInfo](#eventinfo9)     | 是   | 返回的认证结果信息或提示信息。  |
Y
youliang_1314 已提交
76 77 78

**示例:**

Y
youliang_1314 已提交
79 80 81 82 83 84 85 86 87 88
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
// 通过callback获取认证结果
try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    auth.on("result", {
Y
youliang_1314 已提交
89 90 91 92 93 94
        callback: (result: userIAM_userAuth.AuthResultInfo) => {
            console.log("authV9 result " + result.result);
            console.log("authV9 token " + result.token);
            console.log("authV9 remainAttempts " + result.remainAttempts);
            console.log("authV9 lockoutDuration " + result.lockoutDuration);
        }
Y
youliang_1314 已提交
95 96 97 98 99 100 101 102 103 104 105
    });
    auth.start();
    console.log("authV9 start success");
} catch (error) {
    console.log("authV9 error = " + error);
    // do error
}
// 通过callback获取认证过程中的提示信息
try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    auth.on("tip", {
106 107 108 109 110 111 112 113 114
        callback : (result : userIAM_userAuth.TipInfo) => {
            switch (result.tip) {
                case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT:
                // do something;
                case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_DARK:
                // do something;
                default:
                // do others
            }
Y
youliang_1314 已提交
115
        }
Y
youliang_1314 已提交
116 117 118 119 120 121 122 123
    });
    auth.start();
    console.log("authV9 start success");
} catch (error) {
    console.log("authV9 error = " + error);
    // do error
}
```
Y
youliang_1314 已提交
124 125 126 127 128 129 130

## AuthInstance<sup>9+</sup>

执行用户认证的对象。

### on<sup>9+</sup>

Y
youliang_1314 已提交
131
on : (name : AuthEventKey, callback : AuthEvent) => void
Y
youliang_1314 已提交
132

Y
youliang_1314 已提交
133
订阅指定类型的用户认证事件。
Y
youliang_1314 已提交
134

135 136
> **说明:**
> 使用获取到的[AuthInstance](#authinstance9)对象调用该接口进行订阅。
Y
youliang_1314 已提交
137 138 139 140 141

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**

Y
youliang_1314 已提交
142
| 参数名    | 类型                        | 必填 | 说明                       |
Y
youliang_1314 已提交
143
| --------- | -------------------------- | ---- | ------------------------- |
Y
youliang_1314 已提交
144
| name  | [AuthEventKey](#autheventkey9) | 是   | 表示认证事件类型,取值为"result"时,回调函数返回认证结果;取值为"tip"时,回调函数返回认证过程中的提示信息。 |
Y
youliang_1314 已提交
145
| callback  | [AuthEvent](#authevent9)   | 是   | 认证接口的回调函数,用于返回认证结果或认证过程中的提示信息。 |
Y
youliang_1314 已提交
146

Z
zengyawen 已提交
147
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
148

Y
youliang_1314 已提交
149 150 151 152 153 154
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 401 | Incorrect parameters. |
| 12500002 | General operation error. |
Y
youliang_1314 已提交
155 156 157

**示例:**

Y
youliang_1314 已提交
158 159 160 161 162 163 164 165 166 167
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    // 订阅认证结果
    auth.on("result", {
Y
youliang_1314 已提交
168 169 170 171 172 173
        callback: (result: userIAM_userAuth.AuthResultInfo) => {
            console.log("authV9 result " + result.result);
            console.log("authV9 token " + result.token);
            console.log("authV9 remainAttempts " + result.remainAttempts);
            console.log("authV9 lockoutDuration " + result.lockoutDuration);
        }
Y
youliang_1314 已提交
174 175 176
    });
    // 订阅认证过程中的提示信息
    auth.on("tip", {
Y
youliang_1314 已提交
177 178 179 180 181 182 183 184 185 186
        callback : (result : userIAM_userAuth.TipInfo) => {
            switch (result.tip) {
                case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_BRIGHT:
                // do something;
                case userIAM_userAuth.FaceTips.FACE_AUTH_TIP_TOO_DARK:
                // do something;
                default:
                // do others
            }
        }
Y
youliang_1314 已提交
187 188 189 190 191 192 193 194
    });
    auth.start();
    console.log("authV9 start success");
} catch (error) {
    console.log("authV9 error = " + error);
    // do error
}
```
Y
youliang_1314 已提交
195 196 197

### off<sup>9+</sup>

Y
youliang_1314 已提交
198
off : (name : AuthEventKey) => void
Y
youliang_1314 已提交
199

Y
youliang_1314 已提交
200
取消订阅特定类型的认证事件。
Y
youliang_1314 已提交
201

202 203
> **说明:**
> 需要使用已经成功订阅事件的[AuthInstance](#authinstance9)对象调用该接口进行取消订阅。
Y
youliang_1314 已提交
204 205 206

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

Y
youliang_1314 已提交
207
| 名称    | 类型                        | 必填 | 说明                       |
Y
youliang_1314 已提交
208
| --------- | -------------------------- | ---- | ------------------------- |
Y
youliang_1314 已提交
209 210
| name    | [AuthEventKey](#autheventkey9)      | 是   | 表示认证事件类型,取值为"result"时,取消订阅认证结果;取值为"tip"时,取消订阅认证过程中的提示信息。 |

Z
zengyawen 已提交
211
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
212

Y
youliang_1314 已提交
213 214 215 216 217 218
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 401 | Incorrect parameters. |
| 12500002 | General operation error. |
Y
youliang_1314 已提交
219 220 221

**示例:**

Y
youliang_1314 已提交
222 223
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
Y
youliang_1314 已提交
224

Y
youliang_1314 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238
let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;
let auth;
try {
    auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    console.log("get auth instance success");
} catch (error) {
    console.log("get auth instance failed" + error);
}

try {
    // 订阅认证结果
    auth.on("result", {
Y
youliang_1314 已提交
239 240 241 242 243 244
        callback: (result: userIAM_userAuth.AuthResultInfo) => {
            console.log("authV9 result " + result.result);
            console.log("authV9 token " + result.token);
            console.log("authV9 remainAttempts " + result.remainAttempts);
            console.log("authV9 lockoutDuration " + result.lockoutDuration);
        }
Y
youliang_1314 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257
    });
    console.log("subscribe authentication event success");
} catch (error) {
    console.log("subscribe authentication event failed " + error);
}
// 取消订阅认证结果
try {
    auth.off("result");
    console.info("cancel subscribe authentication event success");
} catch (error) {
    console.info("cancel subscribe authentication event failed, error = " + error);
}
```
Y
youliang_1314 已提交
258 259 260

### start<sup>9+</sup>

Y
youliang_1314 已提交
261
start : () => void
Y
youliang_1314 已提交
262

Y
youliang_1314 已提交
263 264 265 266
开始认证。

> **说明:**
> 使用获取到的[AuthInstance](#authinstance9)对象调用该接口进行认证。
Y
youliang_1314 已提交
267 268 269 270 271

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

Z
zengyawen 已提交
272
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
273

Y
youliang_1314 已提交
274 275 276 277 278 279
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 201 | Permission verification failed. |
| 401 | Incorrect parameters. |
Y
youliang_1314 已提交
280
| 12500001 | Authentication failed. |
Y
youliang_1314 已提交
281
| 12500002 | General operation error. |
Y
youliang_1314 已提交
282 283
| 12500003 | The operation is canceled. |
| 12500004 | The operation is time-out. |
Y
youliang_1314 已提交
284 285
| 12500005 | The authentication type is not supported. |
| 12500006 | The authentication trust level is not supported. |
Y
youliang_1314 已提交
286 287
| 12500007 | The authentication task is busy. |
| 12500009 | The authenticator is locked. |
Y
youliang_1314 已提交
288 289
| 12500010 | The type of credential has not been enrolled. |

Y
youliang_1314 已提交
290 291
**示例:**

Y
youliang_1314 已提交
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;

try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    auth.start();
    console.info("authV9 start auth success");
} catch (error) {
    console.info("authV9 start auth failed, error = " + error);
}
```
Y
youliang_1314 已提交
307 308 309

### cancel<sup>9+</sup>

Y
youliang_1314 已提交
310
cancel : () => void
Y
youliang_1314 已提交
311

Y
youliang_1314 已提交
312 313 314
取消认证。

> **说明:**
315
> 使用获取到的[AuthInstance](#authinstance9)对象调用该接口进行取消认证,此[AuthInstance](#authinstance9)需要是正在进行认证的对象。
Y
youliang_1314 已提交
316 317 318 319 320

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

Z
zengyawen 已提交
321
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
322

Y
youliang_1314 已提交
323 324 325 326 327 328 329 330
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 201 | Permission verification failed. |
| 401 | Incorrect parameters. |
| 12500002 | General operation error. |

Y
youliang_1314 已提交
331 332
**示例:**

Y
youliang_1314 已提交
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;

try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    auth.cancel();
    console.info("cancel auth success");
} catch (error) {
    console.info("cancel auth failed, error = " + error);
}
```
Y
youliang_1314 已提交
348 349 350 351 352 353 354 355

## userIAM_userAuth.getAuthInstance<sup>9+</sup>

getAuthInstance(challenge : Uint8Array, authType : UserAuthType, authTrustLevel : AuthTrustLevel): AuthInstance

获取AuthInstance对象,用于执行用户身份认证。

> **说明:**
Y
youliang_1314 已提交
356
> 每个AuthInstance只能进行一次认证,若需要再次进行认证则需重新获取AuthInstance。
Y
youliang_1314 已提交
357 358 359 360 361

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**

Y
youliang_1314 已提交
362
| 参数名         | 类型                                     | 必填 | 说明                     |
Y
youliang_1314 已提交
363 364 365 366 367 368 369 370 371 372 373
| -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge      | Uint8Array                               | 是   | 挑战值,最大长度为32字节,可以填null。     |
| authType       | [UserAuthType](#userauthtype8)           | 是   | 认证类型,当前支持FACE。 |
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8)       | 是   | 认证信任等级。               |

**返回值:**

| 类型                                      | 说明         |
| ----------------------------------------- | ------------ |
| [AuthInstance](#authinstance9) | 认证器对象。 |

Z
zengyawen 已提交
374
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
375

Y
youliang_1314 已提交
376 377 378 379 380 381 382 383 384
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 401 | Incorrect parameters. |
| 12500002 | General operation error. |
| 12500005 | The authentication type is not supported. |
| 12500006 | The authentication trust level is not supported. |

Y
youliang_1314 已提交
385 386
**示例:**

Y
youliang_1314 已提交
387 388
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
Y
youliang_1314 已提交
389

Y
youliang_1314 已提交
390 391 392 393 394 395 396 397 398 399 400
let challenge = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let authType = userIAM_userAuth.UserAuthType.FACE;
let authTrustLevel = userIAM_userAuth.AuthTrustLevel.ATL1;

try {
    let auth = userIAM_userAuth.getAuthInstance(challenge, authType, authTrustLevel);
    console.info("get auth instance success");
} catch (error) {
    console.info("get auth instance success failed, error = " + error);
}
```
Y
youliang_1314 已提交
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

## userIAM_userAuth.getVersion<sup>9+</sup>

getVersion(): number

获取认证器的版本信息。

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**返回值:**

| 类型   | 说明                   |
| ------ | ---------------------- |
Y
youliang_1314 已提交
416 417
| number | 认证器版本信息。 |

Z
zengyawen 已提交
418
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
419

Y
youliang_1314 已提交
420 421 422 423 424 425
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 201 | Permission verification failed. |
| 12500002 | General operation error. |
Y
youliang_1314 已提交
426 427 428

**示例:**

Y
youliang_1314 已提交
429 430
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
Y
youliang_1314 已提交
431

Y
youliang_1314 已提交
432 433 434 435 436 437 438
try {
    let version = userIAM_userAuth.getVersion();
    console.info("auth version = " + version);
} catch (error) {
    console.info("get version failed, error = " + error);
}
```
Y
youliang_1314 已提交
439 440 441 442 443

## userIAM_userAuth.getAvailableStatus<sup>9+</sup>

getAvailableStatus(authType : UserAuthType, authTrustLevel : AuthTrustLevel): void

Y
youliang_1314 已提交
444
查询指定类型和等级的认证能力是否支持。
Y
youliang_1314 已提交
445 446 447 448 449 450 451

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**

Y
youliang_1314 已提交
452
| 参数名         | 类型                               | 必填 | 说明                       |
Y
youliang_1314 已提交
453 454
| -------------- | ---------------------------------- | ---- | -------------------------- |
| authType       | [UserAuthType](#userauthtype8)     | 是   | 认证类型,当前只支持FACE。 |
Y
youliang_1314 已提交
455 456
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是   | 认证信任等级。       |

Z
zengyawen 已提交
457
以下错误码的详细介绍请参见[用户认证错误码](../errorcodes/errorcode-useriam.md)
Y
youliang_1314 已提交
458

Y
youliang_1314 已提交
459 460 461 462 463 464 465 466 467 468
**错误码:**

| 错误码ID | 错误信息 |
| -------- | ------- |
| 201 | Permission verification failed. |
| 401 | Incorrect parameters. |
| 12500002 | General operation error. |
| 12500005 | The authentication type is not supported. |
| 12500006 | The authentication trust level is not supported. |
| 12500010 | The type of credential has not been enrolled. |
Y
youliang_1314 已提交
469 470 471

**示例:**

Y
youliang_1314 已提交
472 473
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
Y
youliang_1314 已提交
474

Y
youliang_1314 已提交
475 476 477 478 479 480 481
try {
    userIAM_userAuth.getAvailableStatus(userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1);
    console.info("current auth trust level is supported");
} catch (error) {
    console.info("current auth trust level is not supported, error = " + error);
}
```
Y
youliang_1314 已提交
482

483
## UserAuthResultCode<sup>9+</sup>
Y
youliang_1314 已提交
484

Y
youliang_1314 已提交
485
表示返回码的枚举。
Y
youliang_1314 已提交
486 487 488

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

Y
youliang_1314 已提交
489
| 名称                    |   值   | 说明                 |
Y
youliang_1314 已提交
490 491
| ----------------------- | ------ | -------------------- |
| SUCCESS                 | 12500000      | 执行成功。           |
Y
youliang_1314 已提交
492
| FAIL                    | 12500001      | 认证失败。           |
Y
youliang_1314 已提交
493 494 495 496 497 498 499 500
| GENERAL_ERROR           | 12500002      | 操作通用错误。       |
| CANCELED                | 12500003      | 操作取消。           |
| TIMEOUT                 | 12500004      | 操作超时。           |
| TYPE_NOT_SUPPORT        | 12500005      | 不支持的认证类型。   |
| TRUST_LEVEL_NOT_SUPPORT | 12500006      | 不支持的认证等级。   |
| BUSY                    | 12500007      | 忙碌状态。           |
| LOCKED                  | 12500009      | 认证器已锁定。       |
| NOT_ENROLLED            | 12500010      | 用户未录入认证信息。 |
501 502

## UserAuth<sup>8+</sup>
Z
zengyawen 已提交
503

Y
youliang_1314 已提交
504
认证器对象。
Z
zengyawen 已提交
505

Y
youliang_1314 已提交
506
### constructor<sup>(deprecated)</sup>
Z
zengyawen 已提交
507

508
constructor()
509

Y
youliang_1314 已提交
510 511
创建认证器对象。

Y
youliang_1314 已提交
512
> **说明:**
Z
zengyawen 已提交
513
> 从 API version 8 开始支持,从 API version 9 开始废弃,请使用[getAuthInstance](#useriam_userauthgetauthinstance9)替代。
Y
youliang_1314 已提交
514

515
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
516

517
**返回值:**
518

519 520
| 类型                   | 说明                 |
| ---------------------- | -------------------- |
Y
youliang_1314 已提交
521
| [UserAuth](#userauth8) | 认证器对象。 |
Z
zengyawen 已提交
522

523
**示例:**
524

Y
youliang_1314 已提交
525 526
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
527

Y
youliang_1314 已提交
528 529
let auth = new userIAM_userAuth.UserAuth();
```
Z
zengyawen 已提交
530

Y
youliang_1314 已提交
531
### getVersion<sup>(deprecated)</sup>
Z
zengyawen 已提交
532

533
getVersion() : number
Z
zengyawen 已提交
534

Y
youliang_1314 已提交
535 536
获取认证器的版本信息。

Y
youliang_1314 已提交
537
> **说明:**
Z
zengyawen 已提交
538
> 从 API version 8 开始支持,从 API version 9 开始废弃,请使用[getVersion](#useriam_userauthgetversion9)替代。
Y
youliang_1314 已提交
539

H
https://gitee.com/WALL_EYE 已提交
540 541
**需要权限**:ohos.permission.ACCESS_BIOMETRIC

542
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
543

544
**返回值:**
545

546 547
| 类型   | 说明                   |
| ------ | ---------------------- |
Y
youliang_1314 已提交
548
| number | 认证器版本信息。 |
549

550
**示例:**
Z
zengyawen 已提交
551

Y
youliang_1314 已提交
552 553
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';
554

Y
youliang_1314 已提交
555 556 557 558
let auth = new userIAM_userAuth.UserAuth();
let version = auth.getVersion();
console.info("auth version = " + version);
```
559

Y
youliang_1314 已提交
560
### getAvailableStatus<sup>(deprecated)</sup>
561

562
getAvailableStatus(authType : UserAuthType, authTrustLevel : AuthTrustLevel) : number
563

Y
youliang_1314 已提交
564 565
查询指定类型和等级的认证能力是否支持。

Y
youliang_1314 已提交
566
> **说明:**
Z
zengyawen 已提交
567
> 从 API version 8 开始支持,从 API version 9 开始废弃,请使用[getAvailableStatus](#useriam_userauthgetavailablestatus9)替代。
Y
youliang_1314 已提交
568

H
https://gitee.com/WALL_EYE 已提交
569 570
**需要权限**:ohos.permission.ACCESS_BIOMETRIC

571
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
572

573
**参数:**
574

Y
youliang_1314 已提交
575
| 参数名         | 类型                               | 必填 | 说明                       |
576 577
| -------------- | ---------------------------------- | ---- | -------------------------- |
| authType       | [UserAuthType](#userauthtype8)     | 是   | 认证类型,当前只支持FACE。 |
Y
youliang_1314 已提交
578
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8) | 是   | 认证信任等级。       |
Z
zengyawen 已提交
579

580
**返回值:**
581

582 583
| 类型   | 说明                                                         |
| ------ | ------------------------------------------------------------ |
Y
youliang_1314 已提交
584
| number | 查询结果,结果为SUCCESS时表示支持,其他返回值参见[ResultCode](#resultcodedeprecated)。 |
Z
zengyawen 已提交
585

586
**示例:**
587

Y
youliang_1314 已提交
588 589 590 591 592 593 594 595 596 597 598
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

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);
}
```
Z
zengyawen 已提交
599

Y
youliang_1314 已提交
600
### auth<sup>(deprecated)</sup>
Z
zengyawen 已提交
601

602
auth(challenge: Uint8Array, authType: UserAuthType, authTrustLevel: AuthTrustLevel, callback: IUserAuthCallback): Uint8Array
Z
zengyawen 已提交
603

Y
youliang_1314 已提交
604 605
执行用户认证,使用回调函数返回结果。

Y
youliang_1314 已提交
606
> **说明:**
Z
zengyawen 已提交
607
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[start](#start9)代替。
Y
youliang_1314 已提交
608

H
https://gitee.com/WALL_EYE 已提交
609 610
**需要权限**:ohos.permission.ACCESS_BIOMETRIC

611
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
612

613
**参数:**
614

Y
youliang_1314 已提交
615
| 参数名         | 类型                                     | 必填 | 说明                     |
616 617 618
| -------------- | ---------------------------------------- | ---- | ------------------------ |
| challenge      | Uint8Array                               | 是   | 挑战值,可以填null。     |
| authType       | [UserAuthType](#userauthtype8)           | 是   | 认证类型,当前支持FACE。 |
619 620
| authTrustLevel | [AuthTrustLevel](#authtrustlevel8)       | 是   | 认证信任等级。             |
| callback       | [IUserAuthCallback](#iuserauthcallbackdeprecated) | 是   | 回调函数。        |
621

622
**返回值:**
623

624 625
| 类型       | 说明                                                         |
| ---------- | ------------------------------------------------------------ |
Y
youliang_1314 已提交
626
| Uint8Array | ContextId,作为取消认证[cancelAuth](#cancelauthdeprecated)接口的入参。 |
Z
zengyawen 已提交
627

628
**示例:**
Z
zengyawen 已提交
629

Y
youliang_1314 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

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 == userIAM_userAuth.ResultCode.SUCCESS) {
                // 此处添加认证成功逻辑
            } else {
                // 此处添加认证失败逻辑
            }
        } catch (e) {
            console.info("auth onResult error = " + e);
        }
    }
});
```
Z
zengyawen 已提交
650

Y
youliang_1314 已提交
651
### cancelAuth<sup>(deprecated)</sup>
Z
zengyawen 已提交
652

653
cancelAuth(contextID : Uint8Array) : number
Z
zengyawen 已提交
654

Y
youliang_1314 已提交
655 656
表示通过contextID取消本次认证操作。

Y
youliang_1314 已提交
657
> **说明:**
Z
zengyawen 已提交
658
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[cancel](#cancel9)代替。
Y
youliang_1314 已提交
659

H
https://gitee.com/WALL_EYE 已提交
660 661
**需要权限**:ohos.permission.ACCESS_BIOMETRIC

662
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
663

664
**参数:**
665

Y
youliang_1314 已提交
666
| 参数名    | 类型       | 必填 | 说明                                       |
667
| --------- | ---------- | ---- | ------------------------------------------ |
Y
youliang_1314 已提交
668
| contextID | Uint8Array | 是   | 上下文的标识,通过[auth](#authdeprecated)接口获取。 |
669

670
**返回值:**
671

672 673
| 类型   | 说明                     |
| ------ | ------------------------ |
Y
youliang_1314 已提交
674
| number | 取消认证的结果,结果为SUCCESS时表示取消成功,其他返回值参见[ResultCode](#resultcodedeprecated)。 |
Z
zengyawen 已提交
675

676
**示例:**
677

Y
youliang_1314 已提交
678 679 680 681 682 683 684 685 686 687 688 689 690
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

// contextId可通过auth接口获取,此处直接定义
let contextId = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]);
let auth = new userIAM_userAuth.UserAuth();
let cancelCode = auth.cancelAuth(contextId);
if (cancelCode == userIAM_userAuth.ResultCode.SUCCESS) {
    console.info("cancel auth success");
} else {
    console.error("cancel auth fail");
}
```
691

Y
youliang_1314 已提交
692 693
## IUserAuthCallback<sup>(deprecated)</sup>

Y
youliang_1314 已提交
694 695
返回认证结果的回调对象。

Y
youliang_1314 已提交
696
> **说明:**
Z
zengyawen 已提交
697
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[AuthEvent](#authevent9)代替。
698

Y
youliang_1314 已提交
699
### onResult<sup>(deprecated)</sup>
700

701
onResult: (result : number, extraInfo : AuthResult) => void
702

Y
youliang_1314 已提交
703 704
回调函数,返回认证结果。

Y
youliang_1314 已提交
705
> **说明:**
Z
zengyawen 已提交
706
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[callback](#callback9)代替。
Y
youliang_1314 已提交
707

708
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
709

710
**参数:**
711

Y
youliang_1314 已提交
712
| 参数名    | 类型                       | 必填 | 说明        |
713 714
| --------- | -------------------------- | ---- | ------------------------------------------------ |
| result    | number           | 是   | 认证结果,参见[ResultCode](#resultcodedeprecated)。 |
Y
youliang_1314 已提交
715
| extraInfo | [AuthResult](#authresultdeprecated) | 是   | 扩展信息,不同情况下的具体信息,<br/>如果身份验证通过,则在extraInfo中返回用户认证令牌,<br/>如果身份验证失败,则在extraInfo中返回剩余的用户认证次数,<br/>如果身份验证执行器被锁定,则在extraInfo中返回冻结时间。 |
716

717
**示例:**
718

Y
youliang_1314 已提交
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

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 == userIAM_userAuth.ResultCode.SUCCESS) {
                // 此处添加认证成功逻辑
            }  else {
                // 此处添加认证失败逻辑
            }
        } catch (e) {
            console.info("auth onResult error = " + e);
        }
    }
});
```
Z
zengyawen 已提交
739

Y
youliang_1314 已提交
740
### onAcquireInfo<sup>(deprecated)</sup>
Z
zengyawen 已提交
741

742
onAcquireInfo ?: (module : number, acquire : number, extraInfo : any) => void
Z
zengyawen 已提交
743

Y
youliang_1314 已提交
744 745
回调函数,返回认证过程中的提示信息,非必须实现。

Y
youliang_1314 已提交
746
> **说明:**
Z
zengyawen 已提交
747
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[callback](#callback9)代替。
Y
youliang_1314 已提交
748

749
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
750

751
**参数:**
Z
zengyawen 已提交
752

Y
youliang_1314 已提交
753
| 参数名    | 类型   | 必填 | 说明                           |
754
| --------- | ------ | ---- | ------------------------------ |
Y
youliang_1314 已提交
755 756
| module    | number | 是   | 发送提示信息的模块标识。             |
| acquire   | number | 是   | 认证执过程中的提示信息。 |
757
| extraInfo | any    | 是   | 预留字段。                     |
Z
zengyawen 已提交
758

759
**示例:**
Z
zengyawen 已提交
760

Y
youliang_1314 已提交
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
```js
import userIAM_userAuth from '@ohos.userIAM.userAuth';

let auth = new userIAM_userAuth.UserAuth();
auth.auth(null, userIAM_userAuth.UserAuthType.FACE, userIAM_userAuth.AuthTrustLevel.ATL1, {
    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);
        }
    }
});
```
777

Y
youliang_1314 已提交
778 779
## AuthResult<sup>(deprecated)</sup>

Y
youliang_1314 已提交
780 781
表示认证结果的对象。

Y
youliang_1314 已提交
782
> **说明:**
Z
zengyawen 已提交
783
> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用[AuthResultInfo](#authresultinfo9)代替。
Z
zengyawen 已提交
784

785
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
786

Y
youliang_1314 已提交
787 788 789
| 名称         | 类型   | 必填 | 说明                 |
| ------------ | ---------- | ---- | -------------------|
| token        | Uint8Array | 否   | 认证通过的令牌信息。 |
790 791 792
| remainTimes  | number     | 否   | 剩余的认证操作次数。 |
| freezingTime | number     | 否   | 认证操作的冻结时间。 |

Y
youliang_1314 已提交
793 794
## ResultCode<sup>(deprecated)</sup>

Y
youliang_1314 已提交
795 796
表示返回码的枚举。

Y
youliang_1314 已提交
797
> **说明:**
798
> 从 API version 9 开始废弃,建议使用[UserAuthResultCode](#userauthresultcode9)代替。
Z
zengyawen 已提交
799

800
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
801

Y
youliang_1314 已提交
802
| 名称                    | 值 | 说明                 |
803 804
| ----------------------- | ------ | -------------------- |
| SUCCESS                 | 0      | 执行成功。           |
Y
youliang_1314 已提交
805
| FAIL                    | 1      | 认证失败。           |
806 807 808 809 810 811
| GENERAL_ERROR           | 2      | 操作通用错误。       |
| CANCELED                | 3      | 操作取消。           |
| TIMEOUT                 | 4      | 操作超时。           |
| TYPE_NOT_SUPPORT        | 5      | 不支持的认证类型。   |
| TRUST_LEVEL_NOT_SUPPORT | 6      | 不支持的认证等级。   |
| BUSY                    | 7      | 忙碌状态。           |
Y
youliang_1314 已提交
812
| INVALID_PARAMETERS      | 8      | 无效参数。           |
813 814
| LOCKED                  | 9      | 认证器已锁定。       |
| NOT_ENROLLED            | 10     | 用户未录入认证信息。 |
Z
zengyawen 已提交
815

816
## FaceTips<sup>8+</sup>
Z
zengyawen 已提交
817

818
表示人脸认证过程中提示码的枚举。
Z
zengyawen 已提交
819

820
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
821

Y
youliang_1314 已提交
822
| 名称                          |   值   |    说明                             |
823 824 825 826 827 828 829 830 831 832 833 834
| ----------------------------- | ------ | ------------------------------------ |
| FACE_AUTH_TIP_TOO_BRIGHT      | 1      | 光线太强,获取的图像太亮。           |
| FACE_AUTH_TIP_TOO_DARK        | 2      | 光线太暗,获取的图像太暗。           |
| FACE_AUTH_TIP_TOO_CLOSE       | 3      | 人脸距离设备过近。                   |
| FACE_AUTH_TIP_TOO_FAR         | 4      | 人脸距离设备过远。                   |
| FACE_AUTH_TIP_TOO_HIGH        | 5      | 设备太高,仅获取到人脸上部。         |
| FACE_AUTH_TIP_TOO_LOW         | 6      | 设备太低,仅获取到人脸下部。         |
| FACE_AUTH_TIP_TOO_RIGHT       | 7      | 设备太靠右,仅获取到人脸右部。       |
| FACE_AUTH_TIP_TOO_LEFT        | 8      | 设备太靠左,仅获取到人脸左部。       |
| FACE_AUTH_TIP_TOO_MUCH_MOTION | 9      | 在图像采集过程中,用户人脸移动太快。 |
| FACE_AUTH_TIP_POOR_GAZE       | 10     | 没有正视摄像头。                     |
| FACE_AUTH_TIP_NOT_DETECTED    | 11     | 没有检测到人脸信息。                 |
Z
zengyawen 已提交
835 836


837
## FingerprintTips<sup>8+</sup>
Z
zengyawen 已提交
838

839
表示指纹认证过程中提示码的枚举。
Z
zengyawen 已提交
840

841
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
842

Y
youliang_1314 已提交
843
| 名称                              |   值   | 说明                                               |
844 845 846 847 848 849 850
| --------------------------------- | ------ | -------------------------------------------------- |
| FINGERPRINT_AUTH_TIP_GOOD         | 0      | 获取的指纹图像良好。                               |
| FINGERPRINT_AUTH_TIP_DIRTY        | 1      | 由于传感器上可疑或检测到的污垢,指纹图像噪音过大。 |
| FINGERPRINT_AUTH_TIP_INSUFFICIENT | 2      | 由于检测到的情况,指纹图像噪声太大,无法处理。     |
| FINGERPRINT_AUTH_TIP_PARTIAL      | 3      | 仅检测到部分指纹图像。                             |
| FINGERPRINT_AUTH_TIP_TOO_FAST     | 4      | 快速移动,指纹图像不完整。                         |
| FINGERPRINT_AUTH_TIP_TOO_SLOW     | 5      | 缺少运动,指纹图像无法读取。                       |
Z
zengyawen 已提交
851 852


853
## UserAuthType<sup>8+</sup>
Z
zengyawen 已提交
854

855
表示身份认证的凭据类型枚举。
Z
zengyawen 已提交
856

857
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
858

Y
youliang_1314 已提交
859
| 名称        |   值   | 说明       |
860 861
| ----------- | ------ | ---------- |
| FACE        | 2      | 人脸认证。 |
862 863
| FINGERPRINT | 4      | 指纹认证。 |

864
## AuthTrustLevel<sup>8+</sup>
865 866 867

表示认证结果的信任等级枚举。

868
**系统能力**:SystemCapability.UserIAM.UserAuth.Core
H
https://gitee.com/WALL_EYE 已提交
869

Y
youliang_1314 已提交
870
| 名称 |   值   | 说明                      |
871 872 873 874
| ---- | ------ | ------------------------- |
| ATL1 | 10000  | 认证结果的信任等级级别1。 |
| ATL2 | 20000  | 认证结果的信任等级级别2。 |
| ATL3 | 30000  | 认证结果的信任等级级别3。 |
875 876 877 878 879 880
| ATL4 | 40000  | 认证结果的信任等级级别4。 |

## userIAM_userAuth.getAuthenticator<sup>(deprecated)</sup>

getAuthenticator(): Authenticator

Y
youliang_1314 已提交
881 882
获取Authenticator对象,用于执行用户身份认证。

883
> **说明:**
Y
youliang_1314 已提交
884
> 从 API version 8 开始废弃,建议使用[constructor](#constructordeprecated)替代。
885 886 887 888

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**返回值:**
889

890 891 892 893 894 895 896 897 898 899 900 901 902
| 类型                                      | 说明         |
| ----------------------------------------- | ------------ |
| [Authenticator](#authenticatordeprecated) | 认证器对象。 |

**示例:**
  ```js
  let authenticator = userIAM_userAuth.getAuthenticator();
  ```

## Authenticator<sup>(deprecated)</sup>

认证器对象。

Y
youliang_1314 已提交
903 904
> **说明:**
> 从 API version 8 开始废弃,建议使用[UserAuth](#userauth8)替代。
905 906 907

### execute<sup>(deprecated)</sup>

Y
youliang_1314 已提交
908
execute(type: AuthType, level: SecureLevel, callback: AsyncCallback&lt;number&gt;): void
909

Y
youliang_1314 已提交
910 911
执行用户认证,使用callback方式作为异步方法。

912
> **说明:**
Y
youliang_1314 已提交
913
> 从 API version 8 开始废弃,建议使用[auth](#authdeprecated)替代。
914 915 916 917 918 919 920

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**

Y
youliang_1314 已提交
921
| 参数名   | 类型                        | 必填 | 说明                      |
922
| -------- | --------------------------- | ---- | -------------------------- |
Y
youliang_1314 已提交
923
| type     | AuthType                      | 是   | 认证类型,当前只支持"FACE_ONLY"。<br/>ALL为预留参数,当前版本暂不支持ALL类型的认证。 |
924
| level    | SecureLevel  | 是   | 安全级别,对应认证的安全级别,有效值为"S1"(最低)、"S2"、"S3"、"S4"(最高)。<br/>具备3D人脸识别能力的设备支持"S3"及以下安全级别的认证。<br/>具备2D人脸识别能力的设备支持"S2"及以下安全级别的认证。 |
Y
youliang_1314 已提交
925
| callback | AsyncCallback&lt;number&gt; | 是   | 回调函数。    |
926

927
callback返回值:
928 929 930 931 932 933

| 类型   | 说明                                                         |
| ------ | ------------------------------------------------------------ |
| number | 表示认证结果,参见[AuthenticationResult](#authenticationresultdeprecated)。 |

**示例:**
Y
youliang_1314 已提交
934 935 936 937 938 939 940 941 942 943 944

```js
let authenticator = userIAM_userAuth.getAuthenticator();
authenticator.execute("FACE_ONLY", "S2", (error, code)=>{
    if (code === userIAM_userAuth.ResultCode.SUCCESS) {
        console.info("auth success");
        return;
    }
    console.error("auth fail, code = " + code);
});
```
945 946 947 948


### execute<sup>(deprecated)</sup>

Y
youliang_1314 已提交
949 950 951
execute(type : AuthType, level : SecureLevel): Promise&lt;number&gt;

执行用户认证,使用promise方式作为异步方法。
952 953

> **说明:**
Y
youliang_1314 已提交
954
> 从 API version 8 开始废弃,建议使用[auth](#authdeprecated)替代。
955 956 957 958 959 960

**需要权限**:ohos.permission.ACCESS_BIOMETRIC

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

**参数:**
961

Y
youliang_1314 已提交
962
| 参数名 | 类型   | 必填 | 说明                                                         |
963
| ------ | ------ | ---- | ------------------------------------------------------------ |
Y
youliang_1314 已提交
964 965
| type   | AuthType | 是   | 认证类型,当前只支持"FACE_ONLY"。<br/>ALL为预留参数,当前版本暂不支持ALL类型的认证。 |
| level  | SecureLevel | 是   | 安全级别,对应认证的安全级别,有效值为"S1"(最低)、"S2"、"S3"、"S4"(最高)。<br/>具备3D人脸识别能力的设备支持"S3"及以下安全级别的认证。<br/>具备2D人脸识别能力的设备支持"S2"及以下安全级别的认证。 |
966 967

**返回值:**
968

969 970 971 972 973 974
| 类型                  | 说明                                                         |
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;number&gt; | 返回携带一个number的Promise。number&nbsp;为认证结果,参见[AuthenticationResult](#authenticationresultdeprecated)。 |

**示例:**

Y
youliang_1314 已提交
975 976 977 978 979 980 981 982
```js
let authenticator = userIAM_userAuth.getAuthenticator();
authenticator.execute("FACE_ONLY", "S2").then((code)=>{
    console.info("auth success");
}).catch((error)=>{
    console.error("auth fail, code = " + error);
});
```
983 984 985

## AuthenticationResult<sup>(deprecated)</sup>

Y
youliang_1314 已提交
986 987
表示认证结果的枚举。

988
> **说明:**
Y
youliang_1314 已提交
989
> 从 API version 8 开始废弃,建议使用[ResultCode](#resultcodedeprecated)替代。
990 991 992

**系统能力**:SystemCapability.UserIAM.UserAuth.Core

Y
youliang_1314 已提交
993
| 名称               |   值   | 说明                       |
994 995 996 997 998 999 1000 1001 1002 1003 1004
| ------------------ | ------ | -------------------------- |
| NO_SUPPORT         | -1     | 设备不支持当前的认证方式。 |
| SUCCESS            | 0      | 认证成功。                 |
| COMPARE_FAILURE    | 1      | 比对失败。                 |
| CANCELED           | 2      | 用户取消认证。             |
| TIMEOUT            | 3      | 认证超时。                 |
| CAMERA_FAIL        | 4      | 开启相机失败。             |
| BUSY               | 5      | 认证服务忙,请稍后重试。   |
| INVALID_PARAMETERS | 6      | 认证参数无效。             |
| LOCKED             | 7      | 认证失败次数过多,已锁定。 |
| NOT_ENROLLED       | 8      | 未录入认证凭据。           |
Y
youliang_1314 已提交
1005
| GENERAL_ERROR      | 100    | 其他错误。                 |