Skip to content

Commit d19f4d2

Browse files
Light version (#7)
Simplified version of the Authentication
1 parent a4f664d commit d19f4d2

File tree

7 files changed

+899
-687
lines changed

7 files changed

+899
-687
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.12.0

README.md

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# Face Authentication Validation Example
22

3-
This project demonstrates a secure face authentication flow using Incode's WebSDK with proper validation and session management. The application implements:
3+
This project demonstrates a secure face authentication flow using Incode's WebSDK with proper backend validation. The application implements:
44

5-
- **User hint input** for authentication (customerId, email, or phone)
5+
- **User hint input** for authentication (identityId)
66
- **Face authentication** using Incode's renderAuthFace SDK
7-
- **Session management** with IndexedDB to prevent reuse
87
- **Backend validation** to verify authentication integrity by:
98
- Matching candidate from the SDK with identityId from the score API
10-
- Validating overall authentication status
11-
- Preventing token tampering and session replay attacks
12-
- Marking sessions as used to prevent reuse
9+
- Validating overall status to be OK
10+
- Closing sessions to prevent modification
1311

1412
This example showcases best practices for implementing face authentication in a web application with proper security measures.
1513

@@ -20,64 +18,48 @@ sequenceDiagram
2018
participant Frontend
2119
participant Backend
2220
participant IncodeAPI
23-
participant IndexedDB
2421
25-
Note over Frontend: Enter hint:<br> identityId
22+
Note over Frontend: Enter hint:<br>identityId
2623
Note over Frontend: WebSDK: create()
2724
Frontend->>Backend: Start Session in Backend<br>{identityId}
2825
Backend->>IncodeAPI: Create new session<br>{configurationId, apikey}
2926
Note over IncodeAPI: /omni/start
30-
IncodeAPI-->>Backend: Returns Session<br>{token, interviewId}
31-
Backend->>IndexedDB: Store session<br>{key: interviewId, backToken: token, status: pending, identityId)
32-
Backend-->>Frontend: Return Session<br>{token, interviewId}
27+
IncodeAPI-->>Backend: Returns Session<br>{token}
28+
Backend-->>Frontend: Return Session<br>{token}
3329
3430
Note over Frontend: WebSDK: renderAuthFace(token, hint)
3531
Note over Frontend: User completes face authentication
3632
Note over Frontend:Returns:<br>{candidate}
3733
38-
Frontend->>Backend: Validate Authentication<br>{interviewId, token, candidate}
39-
Backend->>IndexedDB: Get Session Info:<br>{key:interviewId}
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-
34+
Frontend->>Backend: Get Results<br>{token, candidate}
35+
5636
Backend->>IncodeAPI: Mark session as completed
5737
Note over IncodeAPI: /0/omni/finish-status
5838
IncodeAPI-->>Backend: Return:<br>{redirectionUrl, action}//Unused
5939
60-
Backend->>IncodeAPI: Get Authentication Score<br>{token:backToken}
40+
Backend->>IncodeAPI: Close Session
41+
Note over IncodeAPI: /omni/session/status/set?action=Closed
42+
IncodeAPI-->>Backend: Return:<br>{sessionStatus}//Unused
43+
44+
Backend->>IncodeAPI: Get Authentication Score<br>{token}
6145
Note over IncodeAPI: /0/omni/get/score
62-
IncodeAPI-->>Backend: {status, identityId}
46+
IncodeAPI-->>Backend: {score, identityId}
6347
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}
48+
Backend->>Frontend: {"candidate doesn't match score identityId", isValid:false}
6649
end
50+
6751
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}
52+
Backend->>Frontend: {"Score for this session is not OK", isValid:false}
7053
end
7154
7255
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}
56+
Backend-->>Frontend: Return validation result<br>{"Successful validation", isValid:true, identityId}
7557
Note over Frontend: Show validation results
7658
```
7759

7860
# Requirements
7961

80-
Vite 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.
62+
Vite 8 requires **Node.js ^20.19.0 || >=22.12.0**. Run `node -v` to verify before installing.
8163

8264
# Install
8365

@@ -99,24 +81,22 @@ VITE_FAKE_BACKEND_FLOW_ID=
9981

10082
Remember the Flow holds the backend counter part of the process, some configurations there might affect the behavior of the WebSDK here.
10183

102-
# Fake Backend Server
84+
# Example Backend
10385

10486
Starting and finishing the session must be done in the backend. To simplify development, this
105-
sample includes a `fake_backend.js` file that handles backend operations in the frontend.
87+
sample includes an `example_backend.js` file that handles backend operations in the frontend.
10688

10789
**Important:** Replace this with a proper backend for production. The API key should NEVER be exposed in the frontend.
10890

10991
## Key Backend Functions
11092

111-
- `fakeBackendStart()` - Creates a new session and stores it in IndexedDB with `used: false`
112-
- `fakeBackendFinish()` - Retrieves the finish status from the API
113-
- `fakeBackendGetScore()` - Gets the authentication score from the API
114-
- `fakeBackendValidateAuthentication()` - Validates the authentication by:
115-
- Checking if the session exists and hasn't been used
116-
- Verifying the token matches the stored token
117-
- Comparing candidate with identityId from the score
118-
- Ensuring overall status is "OK"
119-
- Marking the session as used to prevent reuse
93+
- `start(identityId)` - Calls Incode's `/0/omni/start` API to create a new session and returns the session `token`
94+
- `getResults(token, candidate)` - Verifies the authentication by:
95+
- Finishing the session via `/0/omni/finish-status` to trigger score calculation
96+
- Closing the session via `/0/omni/session/status/set?action=Closed` to freeze the score
97+
- Retrieving the score via `/0/omni/get/score`
98+
- Comparing `candidate` (from the WebSDK) with `identityId` from the score to prevent tampering
99+
- Checking that the overall score status is "OK"
120100

121101
# Run
122102

0 commit comments

Comments
 (0)