目录

IFAA Passwordless Authentication

Use Cases

Constraints

Service Process

Registration Process:

  1. The app client calls the getAnonymousIdSync API to obtain the device ID based on the user ID.
  2. The app client obtains the registration data from the app server.
  3. The app client calls the register API to perform registration and obtain the registration packet.
  4. The app client reports the registration packet to the app server. The app server verifies the packet and returns the result.

Authentication Process:

  1. The app client calls the getAnonymousIdSync API to obtain the device ID based on the user ID.
  2. The app client obtains the authentication data from the app server.
  3. The app client calls the preAuthSync API to obtain the challenge for passwordless payment.
  4. The app client requests identity authentication and completes biometric authentication.
  5. The app client calls the auth API to perform IFAA authentication and obtain the authentication packet.
  6. The app client reports the authentication packet to the app server. The app server verifies the packet and returns the result.

Deregistration Process:

  1. The app client calls the getAnonymousIdSync API to obtain the device ID based on the user ID.
  2. The app client obtains the deregistration data from the app server.
  3. The app client calls the deregisterSync API to deregister IFAA.

API Description

The following table lists the APIs required for registration, authentication, and deregistration. For details about the APIs, see API Reference.

API Description
register(registerData: Uint8Array): Promise<Uint8Array> Enables IFAA passwordless authentication and returns the result asynchronously through a promise.
auth(authToken: Uint8Array, authData: Uint8Array): Promise<Uint8Array> Performs IFAA passwordless authentication and returns the result asynchronously through a promise.
deregisterSync(deregisterData: Uint8Array): void Deregisters IFAA passwordless authentication and returns the result synchronously.
getAnonymousIdSync(userToken: Uint8Array): Uint8Array Obtains the anonymous ID for IFAA passwordless authentication and returns the result synchronously.

Development Procedure

  1. Import required modules.

    import { ifaa } from '@kit.OnlineAuthenticationKit';
    import { userAuth } from '@kit.UserAuthenticationKit';
    import { BusinessError } from '@kit.BasicServicesKit';
  2. Enable IFAA passwordless authentication.

    try {
      // Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
      let getAnonIdResult: Uint8Array = ifaa.getAnonymousIdSync(userTokenFp);
      console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
    }
    try {
      // Use getAnonymousIdSync to obtain the signed registration data from the server.
      // Convert the registration data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvRegisterFp, and then call the ifaa.register API.
      let registerPromise: Promise<Uint8Array> = ifaa.register(tlvRegisterFp);
      registerPromise.then(registerResult => {
        console.info('Succeeded in doing register, result:', registerResult);
        // The registration is successful. Obtain and process the ifaa.register result.
        // ...
      }).catch((err: BusinessError) =>{
        console.error(`Failed to call register. Code: ${err.code}, message: ${err.message}`);
        // The registration fails. Obtain the ifaa.register error and handle it.
      });
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to register. Code is ${err.code}, message is ${err.message}`);
    }
  3. Perform IFAA passwordless authentication.

    // Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
    let getAnonIdResult: Uint8Array;
    try {
      getAnonIdResult = ifaa.getAnonymousIdSync(userTokenFp);
      console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
    }
    
    // Use getAnonymousIdSync to obtain the signed authentication data from the server.
    // Obtain challenge of the passwordless payment.
    let ifaaChallenge: Uint8Array = new Uint8Array([0]);
    try {
      ifaaChallenge = ifaa.preAuthSync();
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to pre auth. Code is ${err.code}, message is ${err.message}`);
    }
    let authParam: userAuth.AuthParam = {
      challenge: ifaaChallenge,
      authType: [userAuth.UserAuthType.FINGERPRINT],
      authTrustLevel: userAuth.AuthTrustLevel.ATL4
    };
    
    try {
      let userAuthInstance = userAuth.getUserAuthInstance(authParam, {title: ' '});
      userAuthInstance.on('result', {
        onResult(result) {
          let authToken = result.token;
          try {
            // After biometric features are successfully authenticated, start IFAA authentication.
            console.info('IFAA auth start');
            // Convert the authentication data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvAuthFp, and then call the ifaa.authSync API.
            // Select a synchronous or asynchronous API based on service requirements.
            let authResult: Uint8Array = ifaa.authSync(authToken, tlvAuthFp);
            console.info('Succeeded in auth, result:', authResult);
            // Process authResult.
            // ...
          } catch (error) {
            const err: BusinessError = error as BusinessError;
            console.error(`Failed to call auth. Code is ${err.code}, message is ${err.message}`);
            // ...
          }
        }
      });
      userAuthInstance.start();
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to user auth. Code is ${err.code}, message is ${err.message}`);
    }
  4. Disable IFAA passwordless authentication.

    // Construct the TLV input parameter based on the IIFAA protocol, convert it into Uint8Array to obtain userTokenFp, and call the ifaa.getAnonymousIdSync API.
    try {
      let getAnonIdResult: Uint8Array = ifaa.getAnonymousIdSync(userTokenFp);
      console.info('Succeeded in getting anonymous id, result:', getAnonIdResult);
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to get anonymous id. Code is ${err.code}, message is ${err.message}`);
    }
    
    // Use the result of getAnonymousId to obtain the signed deregistration data from the server.
    // Convert the deregistration data (TLV format of the IIFAA protocol) into Uint8Array to obtain tlvDeregisterRp, and then call the ifaa.deregisterSync API.
    try {
      ifaa.deregisterSync(tlvDeregisterRp);
      // ...
    } catch (error) {
      const err = error as BusinessError;
      console.error(`Failed to deregister. Code is ${err.code}, message is ${err.message}`);
      // ...
    }