harmony 鸿蒙Canceling User Authentication
Canceling User Authentication
Use cancel() to terminate the authentication process when needed.
Available APIs
For details about the parameters, return value, and error codes, see cancel.
This topic describes only the API for canceling authentication. For details about the APIs for initiating authentication, see Initiating Authentication and User Authentication.
API | Description |
---|---|
cancel(): void | Cancels this user authentication. |
How to Develop
Check that the application has the ohos.permission.ACCESS_BIOMETRIC permission. For details about how to request permissions, see Requesting Permissions.
Set AuthParam (including the challenge value, UserAuthType, and AuthTrustLevel), obtain a UserAuthInstance instance, and call UserAuthInstance.start to start authentication. For details, see Initiating Authentication.
Call UserAuthInstance.cancel with the UserAuthInstance instance that has initiated the authentication to terminate the authentication process.
Example: Initiate facial and lock screen password authentication at ATL3 or higher and then cancel it.
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;
// Set authentication parameters.
const authParam: userAuth.AuthParam = {
challenge: randData,
authType: [userAuth.UserAuthType.PIN, userAuth.UserAuthType.FACE],
authTrustLevel: userAuth.AuthTrustLevel.ATL3,
};
// Set the authentication page.
const widgetParam: userAuth.WidgetParam = {
title: 'Verify identity',
};
// Obtain a UserAuthInstance object.
const userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
console.info('get userAuth instance success');
// Start user authentication.
userAuthInstance.start();
console.info('auth start success');
// Cancel the authentication.
userAuthInstance.cancel();
console.info('auth cancel success');
} catch (error) {
const err: BusinessError = error as BusinessError;
console.error(`auth catch error. Code is ${err?.code}, message is ${err?.message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙User Authentication Kit (User Authentication Service)
harmony 鸿蒙Applying Custom Authentication
harmony 鸿蒙Obtaining Enrolled Credential Status
harmony 鸿蒙Obtaining Supported Authentication Capabilities
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦