Online 1 to 1

Description

Once you executed a success onboarding and created the identity of the user, you can use Face Authentications to validate the face of a persons in order to know if it belongs to that user.

Face Authentication is a process where a selfie is taken and then is compared to a previously onboarded user. From this process you can get tokens to do things with incodes API, or simply verify that the users are who they say they are. The general process is:

1.- Take a Selfie

2.- Compare against incode face database directly from front to backend using the renderLogin component

3.- Validate in the backend the authentication attempt is real and was successful using /authentication/verify

Prerequisites

  • An onboarded user
  • The customerUUID of the user identity

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
}
const IncodeSDKInitialize = (API_URL, API_KEY) => {
    IncodeSdk.initialize({
      testMode: false,
      apiConfig: {
        url: API_URL,
        key: API_KEY,
      },
      waitForTutorials: true,
    })
      .then((_) => {
        startOnlineFaceLogin11();
      })
      .catch((e) => {
        console.error('Incode SDK failed init', e);
      });
  };
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();
      },
    );
}
// NOTE:
//
// To Initialize the SDK in Xamarin, you need to add the next code into the Native project
// that Xamarin creates.

// ANDROID
// **************************************************

using System;

using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
using Incode.Onboarding;

namespace IncodeOnboardingApplication.Droid
{
    [Activity(Label = "IncodeOnboardingApplication", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            // TODO - 1 - Set environment configuration
            var API_URL = "";
            var API_KEY = "";

            IncodeOnboarding.Current.Init(
                url: API_URL,
                apiKey: API_KEY,
                isLoggingEnabled: true,
                isTestMode: false
            );

            LoadApplication(new App());
        }
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}

// iOS
// **************************************************
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using Incode.Onboarding;
using UIKit;

namespace IncodeOnboardingApplication.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            // TODO - 1 - Set environment configuration
            var API_URL = "";
            var API_KEY = "";

            IncodeOnboarding.Current.Init(
                url: API_URL,
                apiKey:API_KEY,
                isLoggingEnabled: true,
                isTestMode: false
            );

            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
    }
}

Step 2: Execute Authentication

private void startOnlineFaceLogin11(Activity activity) {
  try {
    SelfieScan selfieScan = new SelfieScan.Builder()
      .setShowTutorials(false)
      .setWaitForTutorials(false)
      .setLensesCheckEnabled(true)
      .setMaskCheckEnabled(true)
      .setMode(SelfieScan.Mode.LOGIN)
      .setCustomerUUID(Constants.CUSTOMER_ID)
      .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, , 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
  }
}
async function startOnlineFaceLogin11() {
  const ret = await IncodeSdk.startFaceLogin({
    faceMaskCheck: true,
    customerUUID: Constant.customerUUID,
  })
  .then((result) => {
    executeBussinessRuleForFaceLogin(result);
  })
  .catch((error) => {
    console.error('Error:' + error);
  });
}

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

      } else {
        // Facelogin failed
      }
    } else {
      // Liveness failed
    }
  } else {
    // Facelogin failed
  }
}
void startOnlineFaceLogin11(){
    IncodeOnboardingSdk.startFaceLogin(
      faceLogin: FaceLogin(customerUUID: Constants.CUSTOMER_UUID, faceMaskCheck: true, lensesCheck: true),
      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
    }
  }
private async void startOnlineFaceLogin11(String uuid, String token)
{
  var result = await IncodeOnboarding.Current.VerifyFace(uuid: uuid, customerToken:token, showTutorials: false, lensesCheck: true, faceMaskCheck: true);

  if (result != null && result.Result == ResultCode.Success)
  {
    if (result.ScanStatus == SelfieScanResult.Status.Ok)
    {
      Debug.WriteLine($"######## Selfie Image in Base 64 => {result.SelfieImage}");

      if (result.SpoofAttempt == false)
      {
        if (result.FaceMatched == true)
        {
          Result.Text = "Face Matched!";
          Debug.WriteLine("######## Verify Face => Face Mathced!");

        }
      }
      else
      {
        // TODO - WARNING - Manage fraud attempt
      }    
    }
    else
    {
      Debug.WriteLine($"######## Verify Face => Fail! due to: {result.ScanStatus}");
    }
  }
  else
  {
    Debug.WriteLine($"######## Verify Face failed!{(result is null ? string.Empty : result.ErrorMessage)}");
  }
}