Skip to content

Commit 171c2a5

Browse files
committed
moved sample server
1 parent 7dbc41c commit 171c2a5

File tree

11 files changed

+2
-810
lines changed

11 files changed

+2
-810
lines changed

.gitignore

Lines changed: 0 additions & 109 deletions
This file was deleted.

sample-server/.dockerignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

sample-server/Dockerfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

sample-server/README.md

Lines changed: 2 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,3 @@
1-
# Example Token Server Using NodeJS
1+
# Sample Moved to its own repo
22

3-
## Endpoints
4-
5-
- GET `/start`: Call Incode's `/omni/start` API to create an Incode session which will include a `token` in the JSON response. This token can be shared with Incode SDK client apps to do token based initialization, which is a best practice.
6-
7-
It also performs basic storage of sessions in the `sessions` directory to help implement `renderRedirectToMobile`in frontend.
8-
9-
At session generation it will generate an `uniqueId` and save the session in `session/<uniqueId>.json`, later if you call `/start` again passing a valid `uniqueId` it will retrieve the stored session instead of creating a new one.
10-
11-
- GET `/onboarding-url`: Calls incodes `/omni/start` and then with the token calls `/0/omni/onboarding-url` to retrieve the unique onboarding-url for the newly created session.
12-
13-
- GET `/onboarding-status`: Calls incodes `/omni/get/onboarding/status` API and return the onboarding status.
14-
15-
Expects `interviewId` as query param.
16-
17-
- GET `/fetch-score`: Calls incodes `/omni/get/score` API and return the score.
18-
19-
Expects `interviewId` as query param.
20-
21-
- POST `/auth`: Receives the information about a faceMatch attempt and verifies if it was correct and has not been tampered.
22-
23-
- POST `/webhook`: Example webhook that reads the json data and return it back a response, from here you could fetch scores or OCR data when the status is ONBOARDING_FINISHED
24-
25-
- POST `/approve`: Example webhook that reads the json data and if the status is ONBOARDING_FINISHED goes ahead and creates the identity using the `/omni/process/approve` endpoint.
26-
27-
## Secure Credential Handling
28-
We highly recommend to follow the 0 rule for your implementations, where all sensitive calls to incode's endpoints are done in the backend, keeping your apikey protected and just returning a `token` with the user session to the frontend.
29-
30-
Within this sample you will find the only calls to a `/omni/` endpoints we recommend for you to have, it requires the usage of the `apikey`, all further calls must be done using only the generated `token` and be addresed to the `/0/omni` endpoints.
31-
32-
## Prerequisites
33-
This sample uses the global fetch API so you must use [Node 18](https://nodejs.org/en) or higher.
34-
35-
## Local Development
36-
37-
### Environment
38-
Rename `sample.env` file to `.env` adding your subscription information:
39-
40-
```env
41-
API_URL=https://demo-api.incodesmile.com
42-
API_KEY=you-api-key
43-
FLOW_ID=Flow or Workflow Id from your Incode dashboard.
44-
ADMIN_TOKEN=Needed for the webhooks to be able to fetch Scores and auto-approve
45-
```
46-
47-
### Using NPM
48-
Install the depencies with `npm install`
49-
```bash
50-
npm install
51-
```
52-
53-
Then start the local server with the nodemon script, it will keep an eye on file changes and restart the local server if needed.
54-
```bash
55-
npm run nodemon
56-
```
57-
58-
The server will accept petitions on `http://localhost:3000/`
59-
60-
### Using Docker
61-
62-
```bash
63-
docker-compose build
64-
docker-compose --env-file ./.env up
65-
```
66-
67-
The server will accept petitions on `http://localhost:3000/`
68-
69-
### Frontend development
70-
71-
For development most of our frontend samples have a reverse proxy configured to serve `http://localhost:3000/` on `https://<your-ip>:5731/api`
72-
73-
That way you avoid all problems related to CORS.
74-
75-
### Webhook development
76-
77-
For our systems to reach your server, you will need to expose the server to the internet with ngrok
78-
79-
For your frontend to properly work in tandem with this server on your mobile phone for testing, you will need a public url with proper SSL configured, by far the easiest way to acchieve this with an ngrok account properly configured on your computer. You can visit `https://ngrok.com` to make a free account and do a quick setup.
80-
81-
Then simply run the nodemon script, it will start the server in port 3000 and restart whenever a file is changed, leave it running.
82-
83-
```bash
84-
npm run nodemon
85-
```
86-
87-
In another shell expose the server to internet through your computer ngrok account:
88-
89-
```bash
90-
ngrok http 3000
91-
```
92-
93-
Open the `Forwarding` adress in a web browser. The URL should look similar to this: `https://466c-47-152-68-211.ngrok-free.app`.
94-
95-
Now you should be able to visit the following routes to receive the associated payloads:
96-
1. `https://yourforwardingurl.app/start`
97-
2. `https://yourforwardingurl.app/start?uniqueId=0e810732-6e7e-4512-aaa5-1ae2e1f8df46`
98-
3. `https://yourforwardingurl.app/onboarding-url`
99-
4. `https://yourforwardingurl.app/onboarding-url?redirectionUrl=https%3A%2F%2Fexample.com%2F`
100-
101-
## Post Endpoints
102-
103-
### Auth
104-
Receives the information about a faceMatch attempt and verifies if it was correct and has not been tampered.
105-
106-
All the parameters needed come as the result of execution of the [Render Login](https://docs.incode.com/docs/web/integration-guide/sdk-methods#renderlogin) component,
107-
you can see a full example of it's usage in [Face Login Sample](https://github.com/Incode-Technologies-Example-Repos/javascript-samples/tree/main/face-login)
108-
109-
```bash
110-
curl --location 'https://yourforwardingurl.app/auth' \
111-
--header 'Content-Type: application/json' \
112-
--data '{
113-
"transactionId": "Transaction Id obtained at face login",
114-
"token": "Token obtained at face login ",
115-
"interviewToken": "Interview token obtained at face login",
116-
}'
117-
```
118-
119-
## Webhooks
120-
121-
### Simplified Webhook
122-
`https://yourforwardingurl.app/webhook`
123-
We provide an example on how to read the data we send in the webhook calls, from here you could
124-
fetch scores and OCR data, what you do with that is up to you.
125-
126-
### Auto approve on PASS
127-
`https://yourforwardingurl.app/approve`
128-
We provide a more complex example where we fetch the scores and if the status is `OK` we then
129-
approve the user to create his identity for face-login
130-
131-
### Admin Token
132-
For the approval and fetching of scores to work you will need an Admin Token, Admin tokens
133-
require an executive user-password and have a 24 hour expiration, thus need a
134-
more involved strategy to be generated, renewed, securely saved and shared to the app.
135-
136-
For this simple test just use the following cURl, and add the generated token to the `.env` file,
137-
you will need to refresh it after 24 hours.
138-
139-
```bash
140-
curl --location 'https://demo-api.incodesmile.com/executive/log-in' \
141-
--header 'Content-Type: application/json' \
142-
--header 'api-version: 1.0' \
143-
--header 'x-api-key: <your-apikey>' \
144-
--data '{
145-
"email": "••••••",
146-
"password": "••••••"
147-
}'
148-
```
149-
150-
### How to test your code
151-
To recreate the call and the format of the data sent by Incode you can use the following script:
152-
153-
```bash
154-
curl --location 'https://yourforwardingurl.app/webhook' \
155-
--header 'Content-Type: application/json' \
156-
--data '{
157-
"interviewId": "<interviewId>",
158-
"onboardingStatus": "ONBOARDING_FINISHED",
159-
"clientId": "<clientId>",
160-
"flowId": "<flowId>"
161-
}'
162-
```
163-
164-
## Dependencies
165-
166-
* **nodejs18+**: JavaScript runtime built on Chrome's V8 JavaScript engine.
167-
* **express**: Web server framework.
168-
* **dotenv**: Used to access environment variables.
169-
* **ngrok**: Unified ingress platform used to expose your local server to the internet.
3+
[backend-nodejs](https://github.com/Incode-Technologies-Example-Repos/backend-nodejs)

sample-server/contract.pdf

-38.6 KB
Binary file not shown.

sample-server/docker-compose.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)