#鸿蒙通关秘籍#用户认证是用来干嘛的?做校验的吗?如何在next中发起一个用户认证?

HarmonyOS
2024-12-06 15:08:48
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
JSON寒霜满地
import { BusinessError } from '@kit.BasicServicesKit';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { userAuth } from '@kit.UserAuthenticationKit';

try {
  const rand = cryptoFramework.createRandom();
  const len: number = 16;
  const randData: Uint8Array = rand?.generateRandomSync(len)?.data;
  const authParam: userAuth.AuthParam = {
    challenge: randData,
    authType: [userAuth.UserAuthType.PIN, userAuth.UserAuthType.FACE],
    authTrustLevel: userAuth.AuthTrustLevel.ATL3,
  };
  const widgetParam: userAuth.WidgetParam = {
    title: '请进行身份认证',
  };

  const userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
  console.info('get userAuth instance success');
  userAuthInstance.on('result', {
    onResult(result) {
      console.info(`userAuthInstance callback result: ${JSON.stringify(result)}`);
      userAuthInstance.off('result');
    }
  });
  console.info('auth on success');
  userAuthInstance.start();
  console.info('auth start success');
} catch (error) {
  const err: BusinessError = error as BusinessError;
  console.error(`auth catch error. Code is ${err?.code}, message is ${err?.message}`);
}
分享
微博
QQ
微信
回复
2024-12-06 16:38:09
相关问题
HarmonyOS 用户认证
24浏览 • 1回复 待解决
HarmonyOS 用户认证问题
177浏览 • 1回复 待解决
用户认证功能有哪些?
960浏览 • 1回复 待解决
HUKS用户认证通过PIN生成密钥
1158浏览 • 1回复 待解决
java主要用来干嘛
8312浏览 • 1回复 待解决