1# @ohos.userIAM.faceAuth (Facial Authentication) 2 3The **userIAM.faceAuth** module provides APIs for face enrollment. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```ts 14import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 15``` 16 17## FaceAuthManager 18 19Provides APIs for facial authentication management. 20 21### constructor 22 23constructor() 24 25A constructor used to create a **FaceAuthManager** object. 26 27**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth 28 29**System API**: This is a system API. 30 31**Return value** 32 33| Type | Description | 34| ---------------------- | -------------------- | 35| [FaceAuthManager](#faceauthmanager) | **FaceAuthManager** object.| 36 37**Example** 38 39```ts 40import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 41 42let faceAuthManager = new userIAM_faceAuth.FaceAuthManager(); 43``` 44 45### setSurfaceId 46 47setSurfaceId(surfaceId: string): void; 48 49Sets an [XComponent surface ID](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid) for the face preview page in the face enrollment process. This API must be used with [AddCredential](./js-apis-osAccount.md#addcredential8). 50 51**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth 52 53**System API**: This is a system API. 54 55**Required permissions**: ohos.permission.MANAGE_USER_IDM 56 57**Parameters** 58 59| Name | Type | Mandatory| Description | 60| -------------- | ---------------------------------- | ---- | -------------------------- | 61| surfaceId | string | Yes | ID of the surface held by the [XComponent](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid).| 62 63For details about the following error codes, see [User Authentication Error Codes](../errorcodes/errorcode-useriam.md). 64 65**Error codes** 66 67| ID| Error Message| 68| -------- | ------- | 69| 201 | Permission verification failed. | 70| 202 | The caller is not a system application. | 71| 12700001 | The operation is failed. | 72 73**Example** 74 75```ts 76import userIAM_faceAuth from '@ohos.userIAM.faceAuth'; 77 78// The surfaceId is obtained from the XComponent control. The surfaceId here is only an example. 79let surfaceId = '123456'; 80let manager = new userIAM_faceAuth.FaceAuthManager(); 81try { 82 manager.setSurfaceId(surfaceId); 83 console.info('set surface id success'); 84} catch (error) { 85 console.error('set surface id failed, error = ' + error); 86} 87``` 88