Skip to content

Commit c4723fe

Browse files
committed
* not sending token
1 parent e96cf06 commit c4723fe

File tree

4 files changed

+36
-63
lines changed

4 files changed

+36
-63
lines changed

README.md

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,42 @@ sequenceDiagram
2020
participant Frontend
2121
participant Backend
2222
participant IncodeAPI
23-
participant IndexedDB
2423
25-
Note over Frontend: Enter hint:<br> identityId
24+
Note over Frontend: Enter hint:<br>identityId
2625
Note over Frontend: WebSDK: create()
2726
Frontend->>Backend: Start Session in Backend<br>{identityId}
2827
Backend->>IncodeAPI: Create new session<br>{configurationId, apikey}
2928
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}
29+
IncodeAPI-->>Backend: Returns Session<br>{token}
30+
Backend-->>Frontend: Return Session<br>{token}
3331
3432
Note over Frontend: WebSDK: renderAuthFace(token, hint)
3533
Note over Frontend: User completes face authentication
3634
Note over Frontend:Returns:<br>{candidate}
3735
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-
36+
Frontend->>Backend: Get Results<br>{token, candidate}
37+
5638
Backend->>IncodeAPI: Mark session as completed
5739
Note over IncodeAPI: /0/omni/finish-status
5840
IncodeAPI-->>Backend: Return:<br>{redirectionUrl, action}//Unused
5941
42+
Backend->>IncodeAPI: Close Session
43+
Note over IncodeAPI: /0/omni/set/status?action=Closed
44+
IncodeAPI-->>Backend: Return:<br>{sessionStatus}//Unused
45+
6046
Backend->>IncodeAPI: Get Authentication Score<br>{token:backToken}
6147
Note over IncodeAPI: /0/omni/get/score
62-
IncodeAPI-->>Backend: {status, identityId}
48+
IncodeAPI-->>Backend: {score, identityId}
6349
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}
50+
Backend->>Frontend: {"candidate doesn't matches score identityId", isVvalid:false}
6651
end
52+
6753
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}
54+
Backend->>Frontend: {"Score for this session is not OK", isValid:false}
7055
end
7156
7257
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}
58+
Backend-->>Frontend: Return validation result<br>{"Succesful validation", isValid:true, identityId}
7559
Note over Frontend: Show validation results
7660
```
7761

example_backend.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,30 @@ const start = async function (identityId) {
3131

3232
// The session response has many values, but you should only pass the token to the frontend.
3333
const responseData = await response.json();
34-
const { token, interviewId } = responseData;
34+
const { token } = responseData;
3535

36-
// Store session in local DB, session will be created as used: false.
37-
await addSession(interviewId, token, identityId);
38-
39-
return { token, interviewId };
36+
return { token };
4037
};
4138

4239
// Public: Verify the authentication by checking the score and session data
43-
const getResults = async function (interviewId, token, candidate) {
44-
45-
// Prevents usage of candidate that doesn't match the identityId stored in session.
46-
if (session.identityId !== candidate) {
47-
// Mark the session as rejected.
48-
await updateSession(interviewId, "rejected");
49-
return {
50-
// Detailed debug message, in production you might want to avoid exposing internal details.
51-
message: "identityId and candidate mismatch for interviewId " + interviewId,
52-
isValid: false,
53-
};
54-
}
40+
const getResults = async function (token, candidate) {
5541

5642
// Finishing the session triggers score calculation and business rules.
5743
await finishStatus(token); // Mark session as finished in Incode backend
44+
5845
// Closing the session stop it from being changed, all /add/ endpoints will be rejected after this, and the score will be frozen.
5946
await setStatusClosed(token); // Mark session as closed in Incode backend
6047

61-
6248
let identityId, scoreStatus;
6349
try {
64-
// At this point we already verified that the token matches, but
65-
// to be clear about our intentions, we use the token stored in the
66-
// database to get the identityId and compare it with the candidate.
6750
const scoreResponse = await getScore(token);
6851
identityId = scoreResponse.authentication.identityId;
6952
scoreStatus = scoreResponse.overall.status;
7053
} catch (e) {
7154
// If there is an error communicating with API, we consider validation failed.
7255
return {
7356
// Detailed debug message, in production you might want to avoid exposing internal details.
74-
message: "Error validating authentication for interviewId " + interviewId + ": " + e.message,
57+
message: "Error validating authentication: " + e.message,
7558
isValid: false,
7659
};
7760
}
@@ -81,7 +64,7 @@ const getResults = async function (interviewId, token, candidate) {
8164
if (identityId !== candidate) {
8265
return {
8366
// Detailed debug message, in production you might want to avoid exposing internal details.
84-
message: "Session data doesn't match for interviewId " + interviewId,
67+
message: "candidate " + candidate + " does not match identityId " + identityId + " from score",
8568
isValid: false,
8669
};
8770
}
@@ -90,15 +73,15 @@ const getResults = async function (interviewId, token, candidate) {
9073
if (scoreStatus !== "OK") {
9174
return {
9275
// Detailed debug message, in production you might want to avoid exposing internal details.
93-
message: "Face Validation failed for interviewId " + interviewId,
76+
message: "Face Validation failed for candidate " + candidate,
9477
isValid: false,
9578
};
9679
}
9780

9881
// Only valid if all checks passed, we return the identityId that was validated.
9982
return {
10083
// Detailed debug message, in production you might want to avoid exposing internal details.
101-
message: "Face Validation succeeded for interviewId " + interviewId,
84+
message: "Face Validation succeeded for candidate " + candidate,
10285
isValid: true,
10386
identityId: identityId,
10487
};
@@ -140,9 +123,17 @@ const setStatusClosed = async function (token) {
140123
} catch (e) {
141124
throw new Error("HTTP Post Error: " + e.message);
142125
}
143-
const results = await response.json();
144-
console.log({results});
145-
return results;
126+
const {sessionStatus} = await response.json();
127+
/* Example response
128+
{
129+
"_id": "69c5c01ac40764536244ac3b",
130+
"_createdAt": 1774567450715,
131+
"_updatedAt": 1774567469629,
132+
"closedAt": 1774567469629,
133+
"sessionStatus": "Closed"
134+
}
135+
*/
136+
return {sessionStatus};
146137
};
147138

148139
// Private: Call Incode's `omni/get/score` API to retrieve the score for the session

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<script src="%VITE_SDK_URL%"></script>
77
<script type="module" src="/main.js"></script>
88
<link href="/style.css" rel="stylesheet" />
9-
<title>Vite WebSDK Example</title>
9+
<title>Incode Authentication Example</title>
1010
</head>
1111
<body>
1212
<main id="app">
1313
<div id="user-hint-container">
1414
<label for="user-hint-input">User Hint (identityId):</label>
15-
<input type="text" id="user-hint-input" placeholder="Enter identityId" />
15+
<input type="text" id="user-hint-input" placeholder="Enter identityId" value="69c5bf1b95cfc94c5fa1f038"/>
1616
<button id="continue-btn">Continue</button>
1717
</div>
1818
<div id="camera-container"></div>

main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@ async function getResults() {
7070
console.log("Getting results of the authentication");
7171
try {
7272
const results = await exampleBackend.getResults(
73-
incodeSession.interviewId,
7473
incodeSession.token,
75-
candidate,
74+
candidate
7675
);
7776
console.log("Result:", results);
7877

7978
const container = document.getElementById("finish-container");
8079
container.innerHTML += `
8180
<hr>
8281
<h2>Authentication Verification</h2>
83-
<p><strong>Interview ID:</strong> ${incodeSession.interviewId}</p>
8482
<p><strong>Candidate:</strong> ${candidate}</p>
8583
<p><strong>Identity ID:</strong> ${results.identityId || "N/A"}</p>
8684
<p><strong>Message:</strong> ${results.message}</p>

0 commit comments

Comments
 (0)