11# Face Authentication Validation Example
2+
23This project demonstrates a secure face authentication flow using Incode's WebSDK with proper validation and session management. The application implements:
34
45- ** User hint input** for authentication (customerId, email, or phone)
@@ -29,43 +30,63 @@ sequenceDiagram
2930 IncodeAPI-->>Backend: Returns Session<br>{token, interviewId}
3031 Backend->>IndexedDB: Store session<br>{key: interviewId, backToken: token, status: pending, identityId)
3132 Backend-->>Frontend: Return Session<br>{token, interviewId}
32-
33+
3334 Note over Frontend: WebSDK: renderAuthFace(token, hint)
3435 Note over Frontend: User completes face authentication
3536 Note over Frontend:Returns:<br>{candidate}
36-
37+
3738 Frontend->>Backend: Validate Authentication<br>{interviewId, token, candidate}
3839 Backend->>IndexedDB: Get Session Info:<br>{key:interviewId}
39- IndexedDB-->>Backend: {backToken, used}
40- Note over Backend: Validate interviewId exists in DB
41- Note over Backend: Validate Session isn't already verified<br>status = pending
42- Note over Backend: Validate<br>candidate = session.identityId
43- Note over Backend: Validate tokens match<br>token = backToken
44-
45- Note over Backend,IndexedDB: Under any error or failed validation
46- Backend->>IndexedDB: Mark session as Rejected<br>{interviewId, status:rejected}
47-
40+ IndexedDB-->>Backend: {backToken, status}
41+ alt interviewId doesn't exist in DB
42+ Backend->>Frontend: {"interviewId doesn't exists", valid:false}
43+ end
44+ alt status != pending
45+ Backend->>Frontend: { "Session was already verified", valid:false}
46+ end
47+ alt candidate != session.identityId
48+ Backend->>IndexedDB: Mark session as Rejected<br>{interviewId, status:rejected}
49+ Backend->>Frontend: {"Stored identityId doesn't match candidate", valid:false}
50+ end
51+ alt token != backToken
52+ Backend->>IndexedDB: Mark session as Rejected<br>{interviewId, status:rejected}
53+ Backend->>Frontend: {"Stored token doesn't match token", valid:false}
54+ end
55+
4856 Backend->>IncodeAPI: Mark session as completed
49- Note over IncodeAPI: /0/omni/finish-status
57+ Note over IncodeAPI: /0/omni/finish-status
5058 IncodeAPI-->>Backend: Return:<br>{redirectionUrl, action}//Unused
5159
5260 Backend->>IncodeAPI: Get Authentication Score<br>{token:backToken}
5361 Note over IncodeAPI: /0/omni/get/score
5462 IncodeAPI-->>Backend: {status, identityId}
55- Note over Backend: Validate candidate matches identityId<br> candidate = identityId
56- Note over Backend: Validate Score is OK:<br>score.status = "OK"
57- Backend->>IndexedDB: Mark session as used<br>{interviewId, status:approved}
58- Backend-->>Frontend: Return validation result<br>{message, valid, identityId}
63+ alt identityId != candidate
64+ Backend->>IndexedDB: Mark session as Rejected<br>{interviewId, status:rejected}
65+ Backend->>Frontend: {"candidate doesn't matches score identityId", valid:false}
66+ end
67+ alt score.status != "OK"
68+ Backend->>IndexedDB: Mark session as Rejected<br>{interviewId, status:rejected}
69+ Backend->>Frontend: {"Score for this session is not OK", valid:false}
70+ end
71+
72+ Note over Backend: Success
73+ Backend->>IndexedDB: Mark session as approved<br>{interviewId, status:approved}
74+ Backend-->>Frontend: Return validation result<br>{"Succesful validation", valid:true, identityId}
5975 Note over Frontend: Show validation results
6076```
6177
6278# Requirements
79+
6380Vite requires Node.js version 14.18+, 16+. some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
6481
6582# Install
83+
6684Run ` npm install `
85+
6786# Config
87+
6888Copy ` .env.example ` to ` .env.local ` and add your local values
89+
6990```
7091VITE_API_URL=https://demo-api.incodesmile.com/0
7192VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.80.1.js
@@ -75,11 +96,13 @@ VITE_FAKE_BACKEND_APIURL=https://demo-api.incodesmile.com
7596VITE_FAKE_BACKEND_APIKEY=
7697VITE_FAKE_BACKEND_FLOW_ID=
7798```
99+
78100Remember the Flow holds the backend counter part of the process, some configurations there might affect the behavior of the WebSDK here.
79101
80102# Fake Backend Server
103+
81104Starting and finishing the session must be done in the backend. To simplify development, this
82- sample includes a ` fake_backend.js ` file that handles backend operations in the frontend.
105+ sample includes a ` fake_backend.js ` file that handles backend operations in the frontend.
83106
84107** Important:** Replace this with a proper backend for production. The API key should NEVER be exposed in the frontend.
85108
@@ -96,21 +119,23 @@ sample includes a `fake_backend.js` file that handles backend operations in the
96119 - Marking the session as used to prevent reuse
97120
98121# Run
122+
99123Vite is configured to serve the project using https and and expose him self, so you can easily test with your mobile phone on the local network.
100124
101125run ` npm run dev `
102126
103127A new server will be exposed, the data will be in the terminal
104128
105129# Build
130+
106131run ` npm run build `
107132
108133A new build will be created in ` /dist ` you can serve that build everywhere just remember to serve with https.
109134
110135# Testing especific versions of the webSDK locally
136+
111137You can save the specific version needed under ` /public ` and change the ` VITE_SDK_URL ` variable on ` .env.local ` to something like:
112138
113139```
114140VITE_SDK_URL=/name-of-the-js-file.js
115141```
116-
0 commit comments