Skip to content

Quick start

Getting started with neomia Pulse API. This example use a web application using JavaScript and a web server written in Python.

Code examples are limited to several programming languages

Only several programming languages are used in the implementation examples. You can use the structures and mechanisms presented to implements clients in other languages.

Frontend (HTML / JavaScript)

You can download the frontend client libraries here : JavaScript Libs.

First, you need to capture data needed by Pulse API from user. Considering a login form, you will have to instance the Pulse Biometric Recorder (PBR) :

Include the script in your HTML page :

1
2
3
<script type="application/javascript" src="pulse-rec.js"></script>
<script type="application/javascript" src="pulse-biometricpass.js"></script>
<script type="application/javascript" src="pulse-animation.js"></script>

Instantiate the neomia Pulse BiometricPass in a javascript file :

1
const biometricPass = new PulseBiometricPass();

Then, add your custom event to get the typing pattern :

1
2
3
4
5
biometricPass.addEventListener('complete', (pattern) => {
    console.log(pattern); // Your Pulse pattern
    /* You can perform the 'user verify' procedure  */
    sendPatternToMyBackend(pattern); // See function bellow...
});

Next, when you are ready to capture the keystroke dynamics, display the biometrics pass :

1
biometricPass.show();

Finally, you have to send it to your backend web server :

1
2
3
4
5
6
7
8
function sendPatternToMyBackend(pattern) {
    fetch("/my-endpoint", {
        method:'POST',
        body:JSON.stringify({
            'pattern':pattern
        });
    });
}

Backend (Python)

The backend is the link between the frontend that collect biometric data and Pulse API services. The flow is: bootstrap the user (to obtain the X-Pulse-Session header and the user's state), then verify the received pattern :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests

PULSE_API_URL = 'https://api.neomia.ai/pulse'
HEADERS = {'apikey': '<APIKEY>'}

user_ref = 'john.doe@example.com'
typing_pattern = data['pattern']

# 1. Bootstrap: resolve the user and obtain the session header.
bootstrap = requests.get(f'{PULSE_API_URL}/users/{user_ref}', headers=HEADERS)
session_id = bootstrap.headers['X-Pulse-Session']

if bootstrap.status_code == 404:
    # Unknown user: create it, then enroll reference patterns
    # (POST /users/{user_ref}/typing-patterns) before verifying.
    ...

# 2. Verify the typing pattern.
response = requests.post(
    f'{PULSE_API_URL}/users/{user_ref}/verify',
    json=typing_pattern,
    headers={**HEADERS, 'X-Pulse-Session': session_id},
)
Send the end-user IP

Set the ip field of the pattern to the end-user's address before relaying it — otherwise Pulse sees your server's IP, which degrades the network, location and impossible-travel indicators.

Then you receive an authentication response from Pulse API, and you can use the result to authenticate, not authenticate or ask another authentication factor according to your authentication policy :

1
2
3
4
5
response = response.json()
is_authenticated = response['authentication']['authenticated']
confidence_score = response['authentication']['confidence']
recommended_action = response['authentication']['recommendedAction']
next_attempt = response['nextAttempt']  # populated when the attempt failed

If the recommended_action is auth, the user is authenticated by Pulse ! If the attempt failed, nextAttempt tells you whether to propose another biometric attempt or the security-code fallback (when the authentication policy enables it).

Error handling is missing

This is a very simple example to illustrate the implementation of Pulse services. User authentication is a critical process, thus you have to add error handling :

  • Missing or malformed data sended by the frontend client.
  • Error from Pulse API. The service can be temporarily unavailable.

You will learn more about the implementation by visiting Pulse API Endpoints and JavaScript Libraries.