openharmony 鸿蒙 ohos-useriam-userauthicon

2025-06-12 浏览 (1)

@ohos.userIAM.userAuthIcon (Embedded User Authentication Widget)

The system provides userAuthIcon to simplify the user authentication process. With userAuthIcon, you can:

  • Easily integrate the facial authentication and fingerprint authentication icons into your applications.

  • Customize the color and size of the icons. The icon style cannot be changed.

  • Start the facial or fingerprint authentication pop-up component once the icon is tapped.

NOTE

The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { userAuth, UserAuthIcon } from '@kit.UserAuthenticationKit';

Child Components

None.

Attributes

The universal attributes are not supported.

UserAuthIcon

UserAuthIcon({ authParam: userAuth.AuthParam, widgetParam: userAuth.WidgetParam, iconHeight?: Dimension, iconColor?: ResourceColor, onIconClick?: ()=>void, onAuthResult: (result: userAuth.UserAuthResult)=>void })

Decorator: @Component

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.UserIAM.UserAuth.Core

Parameters

NameTypeMandatoryDescription
authParamAuthParamYesUser authentication parameters.
widgetParamWidgetParamYesParameters on the user authentication page.
iconHeightDimensionNoHeight of the icon.
The aspect ratio is 1:1.
The default value is 64.
iconColorResourceColorNoColor of the icon. The default value is $r('sys.color.ohos_id_color_activated').
onIconClick()=>voidNoCallback to be invoked when the icon is tapped.
onAuthResult(result: UserAuthResult)=>voidYesCallback used to return the user authentication result.
Required permissions: ohos.permission.ACCESS_BIOMETRIC

Events

Universal events are not supported.

Example

import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { userAuth, UserAuthIcon } from '@kit.UserAuthenticationKit';

@Entry
@Component
struct Index {
  rand = cryptoFramework.createRandom();
  len: number = 16;
  randData: Uint8Array = this.rand?.generateRandomSync(this.len)?.data;
  authParam: userAuth.AuthParam = {
    challenge: this.randData,
    authType: [userAuth.UserAuthType.FACE, userAuth.UserAuthType.PIN],
    authTrustLevel: userAuth.AuthTrustLevel.ATL3
  };
  widgetParam: userAuth.WidgetParam = {
    title: 'Verify identity'
  };

  build() {
    Row() {
      Column() {
        UserAuthIcon({
          authParam: this.authParam,
          widgetParam: this.widgetParam,
          iconHeight: 200,
          iconColor: Color.Blue,
          onIconClick: () => {
            console.info('The user clicked the icon.');
          },
          onAuthResult: (result: userAuth.UserAuthResult) => {
            console.info(`Get user auth result, result = ${JSON.stringify(result)}`);
          }
        })
      }
    }
  }
}

An error may be thrown when onAuthResult is called. For details about the error codes, see User Authentication Error Codes.

Facial authentication icon

Face Icon

Fingerprint authentication icon

Fingerprint icon

你可能感兴趣的鸿蒙文章

harmony 鸿蒙User Authentication Kit (User Authentication Service)

harmony 鸿蒙User Authentication Error Codes

harmony 鸿蒙@ohos.userIAM.faceAuth (Facial Authentication) (System API)

harmony 鸿蒙@ohos.userIAM.userAccessCtrl (User Access Control) (System API)

harmony 鸿蒙@ohos.userIAM.userAuth (User Authentication) (System API)

harmony 鸿蒙@ohos.userIAM.userAuth (User Authentication)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/MdyhSA