Read the original article:How to use authentication using Athentication Kit
Introduction
User Authentication Kit provides the user authentication capabilities based on the lock screen password, facial characteristics, and fingerprint registered with a device.
User Authentication Kit provides system-level identity authentication and a system-level user authentication widget, which provides unified user authentication across devices with diversified authentication modes (facial, fingerprint, and PIN authentication).
Features
- Unified authentication interface
- Unified APIs are provided to perform user authentication based on the lock screen password, facial characteristics, and fingerprint.
- The same set of APIs provides a combination of facial, fingerprint, and lock screen password authentication modes.
- The same set of APIs provides a combination of facial authentication, fingerprint authentication, and custom authentication
- Awareness of different authentication trust levels
- The expected authentication trust level can be specified to prevent the use of the lower-security authentication capability (such as the 2D facial authentication) in user authentication scenarios with higher risks (such as payment).
- Support for custom authentication modes
- The authentication page with a navigation button is provided for the user to switch to a page for custom authentication.
- Reuse of the authentication result of any application within a short period of time
- The successful result of the previous authentication can be reused within the specified period of time (max. 5 minutes). The following reuse modes are supported:
- Reuse of the lock screen authentication result or identity authentication result of any application within the specified time period.
- Reuse of the authentication result within the specified time period no matter whether the type of the current authentication matches that of the previous one.
- Reuse of the authentication result within the specified time period only when the type of the current authentication matches that of the previous one.
- System-level user authentication UX
- The caller can customize the title of the authentication page and the text on the navigation button.
- The user authentication widget automatically adjusts the display mode based on the device screen status.
- Awareness of the change in credential status
- The status of the credentials enrolled by a user can be directly queried or obtained from the authentication and saved. To check whether a user credential is changed, the caller can query the current credential status or obtain the credential status from the current authentication, and compare the credential status obtained with the credential status saved.
How to implements to Arkts
import { BusinessError } from '@kit.BasicServicesKit';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { userAuth } from '@kit.UserAuthenticationKit';
try {
const rand = cryptoFramework.createRandom();
const len: number = 16; // Generate a 16-byte random number.
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');
// Subscribe to the authentication result.
userAuthInstance.on('result', {
onResult(result) {
console.info(`userAuthInstance callback result: ${JSON.stringify(result)}`);
// Unsubscribe from the authentication result if required.
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}`);
}
Conclusion
Huawei Authentication Kit provides a secure, fast, and user-friendly authentication solution for mobile applications. With support for advanced biometric features such as facial recognition and fingerprint verification, it enhances both user experience and app security. Seamlessly integrated with HMS Core, it offers developers easy implementation and robust technical support. By prioritizing privacy and accuracy, Authentication Kit stands out as an ideal choice for modern mobile apps that require reliable and secure user identity verification.
Top comments (0)