Offline 1 to 1

Description

The only difference against an [Online Authentication](authentication - mobile - 1_1) is changing the faceAuth mode, to let the SDK that needs to use the biometric template stored in the device (in a secure way) and compare against the selfie capture.

In order to change the faceAuth mode you need to add this line of code:

.setFaceAuthMode(SelfieScan.FaceAuthMode.LOCAL)
IncdOnboardingManager.shared.startFaceLogin(..., faceAuthMode: FaceAuthMode.local, ...)
faceLogin: FaceLogin(.., faceAuthMode: FaceAuthMode.local, ...)

Prerequisites

In order to be able to execute an Authentication in offline mode (No Internet connection needed) the user needs to have executed a complete and success onboarding in the same device.

Guide

Step 1: Initialize the Incode SDK

public static void IncodeSDKInitialize(Application app) {
  try {

    new IncodeWelcome.Builder(app, Constants.API_URL, Constants.API_KEY)
      .setLoggingEnabled(true)
      .build();

    incodeSDKInitialized = true;
  } catch (Exception exception) {
    incodeSDKInitialized = false;
  }
}

private void setIncodeCommonConfig() {
  CommonConfig commonConfig = new com.incode.welcome_sdk.CommonConfig.Builder()
    .setShowExitConfirmation(true)
    .setShowCloseButton(true)
    .build();

  IncodeWelcome.getInstance().setCommonConfig(commonConfig);
}
func incodeSDKInitialize(api_url: String, api_key: String) {
  IncdOnboardingManager.shared.initIncdOnboarding(url: api_url,
                                                  apiKey: api_key,
                                                  loggingEnabled: true,
                                                  testMode: testMode) { (success, error) in
        print("IncdOnboarding SDK initialization, success: \(success == true), error: \(error?.description ?? "nil")")
        self.dispatchGroup.leave()
    }
}

func setIncodeCommonConfig() {
  IncdOnboardingManager.shared.allowUserToCancel = true
  IncdOnboardingManager.shared.idBackShownAsFrontCheck = true
  IncdOnboardingManager.shared.idFrontShownAsBackCheck = true
}
void IncodeSDKInitialize(API_URL,API_KEY) {
	IncodeOnboardingSdk.init(
      apiKey: API_KEY,
      apiUrl: API_URL,
      onError: (String error) {
        print('Incode SDK init failed: $error');
      },
      onSuccess: () {
        onStartOnboarding();
      },
    );
}

Step 2: Execute Authentication

private void startOfflineFaceLogin11(Activity activity) {
  try {
    SelfieScan selfieScan = new SelfieScan.Builder()
      .setShowTutorials(false)
      .setWaitForTutorials(false)
      .setLensesCheckEnabled(true)
      .setMaskCheckEnabled(true)
      .setMode(SelfieScan.Mode.LOGIN)
      .setCustomerUUID(Constants.CUSTOMER_ID)
      .setFaceAuthMode(SelfieScan.FaceAuthMode.LOCAL)
      .build();

    IncodeWelcome.getInstance().startFaceLogin(activity, selfieScan, new SelfieScanListener() {
      @Override
      public void onSelfieScanCompleted(SelfieScanResult selfieScanResult) {
      	Timber.d("FACELOGIN 1:1 -> %s", selfieScan.toString());
				
      	executeBussinessRuleForFaceLogin(selfieScanResult);
    	}

    	@Override
    	public void onError(Throwable error) {
      	// TODO - Manage any module error
    	}

    	@Override
   		public void onUserCancelled() {
      	// TODO - Manage user cancellation
      	// TODO - Write the code to clean variable if needed, or move to the specific screen
      	// TODO - Example - finish()
    	}
  	});
  } catch (Exception e) {
    e.printStackTrace();
  }
}

private void executeBussinessRuleForFaceLogin(SelfieScanResult selfieScanResult) {
  if (selfieScanResult.status == SelfieScanResult.STATUS_OK) {
    if (selfieScanResult.isFaceMatched == true) {
      if (selfieScanResult.isSpoofAttempt == false) {
        // User's face is not similar to previously enrolled face
        if (selfieScanResult.faceLoginResult.success == true) {
          if (selfieScanResult.faceLoginResult.customerUUID != null) {

          } else {

          }
        } else {

        }
      } else {
        // Liveness failed
      }
    } else {

    }
  } else {
    // Some of the preconditions for checking liveness failed, check selfieScanResult.status for specific info
  }
}
func startOnlineFaceLogin11(){
  IncdOnboardingManager.shared.presentingViewController = self;
IncdOnboardingManager.shared.startFaceLogin(customerUUID: Constant.CUSTOMER_UUID, faceAuthMode: FaceAuthMode.local, lensesCheck: true, faceMaskCheck: true) { result in
   self.executeBussinessRuleForFaceLogin(result)
  }
}

func executeBussinessRuleForFaceLogin(_ result:SelfieScanResult) {
  if (result.error == nil) {
    if (result.spoofAttempt == false) {
      if(result.faceLoginResult != nil) {
        if (result.faceLoginResult!.success == true) {
          if (result.faceLoginResult!.customerUUID != nil) {

          } else {
            // Not user found
          }
        } else {
          // Not user found
        }
      }
      else{
        // Facelogin failed
      }
    } else {
      // Liveness failed
    }
  } else {
    // Facelogin failed
  }
}
void startOnlineFaceLogin11(){
    IncodeOnboardingSdk.startFaceLogin(
      faceLogin: FaceLogin(customerUUID: Constants.CUSTOMER_UUID, faceMaskCheck: true, lensesCheck: true, faceAuthMode: FaceAuthMode.local),
      onSuccess: (FaceLoginResult result) {
        executeBussinessRuleForFaceLogin(result);
      },
      onError: (String error) {
        print(error);
      },
    );
  }

  void executeBussinessRuleForFaceLogin(result) {
    if (result.faceMatched == true) {
      if (result.spoofAttempt == false) {
        if (result.customerUUID != null) {

        } else {
          // Facelogin failed
        }
      } else {
        // Liveness failed
      }
    } else {
      // Facelogin failed
    }
  }