Skip to content

Commit e40e682

Browse files
Merge pull request #1 from Incode-Technologies-Example-Repos/move-to-one-on-one-default
Making 1:1 the default for face authentication example
2 parents dea8b9f + bca9d33 commit e40e682

File tree

5 files changed

+88
-1003
lines changed

5 files changed

+88
-1003
lines changed

face-login/.env.example

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
VITE_TOKEN_SERVER_URL=/api
2-
VITE_CLIENT_ID=<your client id>
32
VITE_API_URL=https://demo-api.incodesmile.com
4-
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.68.0.js
5-
VITE_API_KEY=<your api key>
3+
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.70.0.js
4+
5+
#Enable for 1:N
6+
#VITE_CLIENT_ID=incode
7+
#VITE_API_KEY=d4c7ef536c0d8e849d39ebb38ec43a96ef06c184

face-login/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sequenceDiagram
88
participant a as API
99
1010
note over w: create()
11-
note over w: renderLogin()<br>Optionally Send customerId for 1:1
11+
note over w: renderLogin()<br>Send identityId for 1:1
1212
alt faceMatch==false
1313
note over w: User doesn't exists
1414
else
@@ -51,11 +51,12 @@ Copy `.env.example` to `.env.local` and add your local values
5151
```
5252
VITE_TOKEN_SERVER_URL=/api
5353
VITE_API_URL=https://demo-api.incodesmile.com
54-
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.68.0.js
55-
VITE_CLIENT_ID=
56-
VITE_API_KEY=<your api key>
57-
```
54+
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.70.0.js
5855
56+
#Enable for 1:N
57+
#VITE_CLIENT_ID=<your client id>
58+
#VITE_API_KEY=<your api key>
59+
```
5960

6061
# Run
6162
Vite is configured to serve the project using https and and expose him self,

face-login/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
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>Face Authentication Example</title>
1010
</head>
1111
<body>
12-
<main id="app">
13-
<div id="container"></div>
14-
</main>
12+
<div id="login" style="display: none;">
13+
<label for="identity-id">Customer ID:</label>
14+
<input id="identity-id" type="text" autofocus></input>
15+
<button id="login-button">Login</button>
16+
</div>
17+
<main id="app"></main>
1518
</body>
1619
</html>

face-login/main.js

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,81 @@
11
const tokenServerURL= import.meta.env.VITE_TOKEN_SERVER_URL
22
let onBoarding;
3-
const container = document.getElementById("container");
3+
4+
const mainContainer = document.getElementById("app");
5+
const loginContainer = document.getElementById("login");
6+
const loginButton = document.getElementById("login-button");
7+
48

59
function showError(e=null) {
6-
container.innerHTML = "<h1>Something Went Wrong, see console for details</h1>";
7-
console.dir(e)
10+
mainContainer.innerHTML = "Something Went Wrong, see console for details...";
11+
console.log(e)
812
}
913

10-
function identifyUser(){
11-
onBoarding.renderLogin(container,{
14+
function identifyUser(identityId){
15+
onBoarding.renderLogin(mainContainer,{
1216
onSuccess: async (response) => {
1317
const {token, transactionId, interviewToken, faceMatch, customerId, email} = response;
1418
if (faceMatch){
1519
// User has an Incode Identity.
1620
// Verify using your backend that the faceMatch was actually valid and
1721
// not man in the middle attack
1822
const response = await fetch(`${tokenServerURL}/auth`,
19-
{
23+
{
2024
method: "POST",
2125
mode: "cors",
2226
body: JSON.stringify({token,transactionId: transactionId, interviewToken})
23-
}
24-
);
25-
const verification = await response.json();
26-
if(verification.verified===true){
27-
finish(customerId, email);
28-
} else {
29-
showError(new Error("FaceMatch is invalid."));
3027
}
28+
);
29+
const verification = await response.json();
30+
if(verification.verified===true){
31+
finish(customerId, email);
3132
} else {
32-
showError(new Error("Face did not match any user."));
33+
showError(new Error("FaceMatch is invalid."));
3334
}
34-
},
35-
onError: error => {
36-
showError(error)
37-
// User not found. Add rejection your logic here
38-
},
39-
// isOneToOne: true,
40-
// oneToOneProps: {
41-
// identityId: "uuid/customerId of the user you want to match",
42-
// }
43-
});
35+
} else {
36+
showError(new Error("Face did not match any user."));
37+
}
38+
},
39+
onError: error => {
40+
showError(error)
41+
// User not found. Add rejection your logic here
42+
},
43+
isOneToOne: true,
44+
oneToOneProps: {
45+
identityId: identityId,
46+
}
47+
});
4448
}
4549

4650
function finish(customerId, email) {
47-
container.innerHTML = `<h1>Sucessfull Login:</h1>\n<p>CustomerId: ${customerId}</p>\n<p>Email: ${email}</p>`;
51+
mainContainer.innerHTML = `Sucessfull Login:<br/>\n<div>CustomerId: ${customerId}</div>\n<div>Email: ${email}</div>`;
4852
}
4953

5054
async function app() {
51-
try {
52-
// Create the instance of incode linked to a client
53-
const apiURL = import.meta.env.VITE_API_URL;
54-
const clientId = import.meta.env.VITE_CLIENT_ID;
55-
const apiKey = import.meta.env.VITE_API_KEY;
56-
57-
onBoarding = window.OnBoarding.create({clientId, apiURL, apiKey});
58-
59-
// Incode web_sdk need to preload some core component before being usable
60-
container.innerHTML = "<h1>Warming up...</h1>";
61-
await onBoarding.warmup();
62-
63-
// Empty the container and starting the flow
64-
container.innerHTML = "";
65-
identifyUser();
66-
} catch (e) {
67-
showError(e);
68-
}
55+
// Create the instance of incode linked to a client
56+
const apiURL = import.meta.env.VITE_API_URL;
57+
// Enable for 1:N
58+
//const clientId = import.meta.env.VITE_CLIENT_ID;
59+
//const apiKey = import.meta.env.VITE_API_KEY;
60+
61+
onBoarding = window.OnBoarding.create({
62+
apiURL
63+
// clientId, // Enable for 1:N
64+
// apiKey // Enable for 1:N
65+
});
66+
67+
// Incode web_sdk need to preload some core component before being usable
68+
mainContainer.innerHTML = "Warming up...";
69+
await onBoarding.warmup();
70+
71+
// Empty the message and starting the flow
72+
mainContainer.innerHTML = "";
73+
loginContainer.style.display="flex";
74+
loginButton.addEventListener('click', () =>{
75+
const identityIdInput = document.getElementById("identity-id");
76+
loginContainer.style.display="none";
77+
identifyUser(identityIdInput.value)
78+
})
6979
}
70-
80+
+
7181
document.addEventListener("DOMContentLoaded", app);

0 commit comments

Comments
 (0)