# DeviceAssure Web Client
## Table of Contents
- [Introduction](#introduction)
- [Client to server model](#client-to-server-model)
- [Server to server model](#server-to-server-model)
- [Supported Browsers](#supported-browsers)
- [Sample Application](#sample-application)
- [Data](#data)
- [Getting Started](#getting-started)
- [Client to Server](#client-to-server-usage)
- [Page Load Setup](#c2s-page-load-setup)
- [User Event Setup](#c2s-user-event-setup)
- [Server to Server](#server-to-server-usage)
- [Page Load Setup](#s2s-page-load-setup)
- [User Event Setup](#s2s-user-event-setup)
- [IMEI Corroboration](#imei-corroboration)
- [Client to Server with IMEI](#imei-corroboration-c2s)
- [Server to Server with IMEI](#imei-corroboration-s2s)
- [Error Handling](#imei-corroboration-error-handling)
- [DeviceAssure Cache Configuration](#deviceassure-cache-configuration)
- [Storage Types/Location](#storage-typeslocation)
- [Cache Expiry Configuration](#cache-expiry-configuration)
- [Troubleshooting](#troubleshooting)
- [iFrame](#iframe-usage)
- [Alternative Setups](#alternative-setups)
- [Using Javascript Modules](#alternative-setups-javascript-modules)
- [Vue, Angular, React etc](#alternative-setups-vue-angular-react-etc)
Introduction
The purpose of this JavaScript library is to analyse and validate a device
visiting a webpage with the library embedded. The collected data is compared
with sets of known valid characteristics for legitimate devices. This
comparison and validation is performed by the DeviceAssure backend service.
The data collected by the library may be sent to the DeviceAssure service in two
ways.
Client to server model
The data is sent directly from the client library to the DeviceAssure backend
service. Validation results are returned to the library and optionally to a
configured callback URL.
Server to server model
The data is collected and made available on the client. The DeviceAssure library
will not make a request to the DeviceAssure service. It is the responsibility of
the calling application to transmit the data to a suitable server and for that
server to make the request to the DeviceAssure service. The validation results
are returned directly back to the calling server and not to the client
application.
---
Supported Browsers
DeviceAssure can reliably identify and verify devices running on browsers. The table below describes the most common browsers that can be identified.
[//]: # (✅ is a check mark emoji)
[//]: # ( is a white space, in order to show empty cells in the table)
| Browser | Android | iOS | Windows | MacOS | Linux |
|-----------------|---------|---------|---------|---------|---------|
| Chrome | ✅ | ✅ | ✅ | ✅ | ✅ |
| Edge | ✅ | ✅ | ✅ | ✅ | ✅ |
| Opera | ✅ | ✅ | ✅ | ✅ | ✅ |
| Firefox* | ✅ | ✅ | ✅ | ✅ | ✅ |
| Brave* | ✅ | ✅ | ✅ | ✅ | ✅ |
| Duck Duck Go | ✅ | ✅ | ✅ | ✅ | |
| Samsung Browser | ✅ | | | | |
| Safari | | ✅ | | ✅ | |
| IE 11 | | | ✅ | | |
#### Note: ####
In addition to identifying the browsers above, DeviceAssure can identify and verify the device model except on Firefox
and Brave as the identifying properties are withheld by the browser.
There is an exception for iOS devices running Firefox and Brave browsers. Due to Apple restrictions, all browsers on iOS must use the WebKit engine and therefore
it is possible to identify the device model on these browsers.
A more detailed browser list DeviceAssure identifies can be found [here](https://deviceatlas.com/device-data/explorer/#defined_property_values/7/2705619).
---
Sample Application
A sample application is included in the package. It includes examples for the following scenarios:
- Client to Server
- On Page Load
- On User Event
- On User Event with IMEI
- Server to Server
- On Page Load
- On User Event
- On User Event with IMEI
- QR Code
A valid DeviceAssure licence key is required for the "Client to Server" examples as these will call the DeviceAssure API from the client.
To correctly identify an Android device or Desktop using the Chrome browser, or any browser that supports client-hints, data collection must occur over a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#potentially_trustworthy_origins).
#### Running the Sample Application ####
```bash
# Unzip the package and navigate to the SampleApplication directory
cd SampleApplication
python3 -m http.server 3000
# Now navigate to http://localhost:3000
```
---
Data
The library collects data about the underlying hardware and browser
capabilities. It does not collect any PII data.
The library stores our data in a configurable location to prevent subsequent calls to the
DeviceAssure library for a **30 minute** period. DeviceAssure will not be called
again until the cache expires or is deleted.
It is possible to delete the cached location within our library. The expiry and the location of the cache can be set, or
can be disabled entirely.
Please see the DeviceAssure Cache Configuration section for more details.
> **Note:** To collect the most complete set of device data—including client-hints from Chromium-based browsers such as Chrome, ensure that your site is served over a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#potentially_trustworthy_origins) (typically HTTPS). Some browser features and data, including client-hints, are only available when the page is loaded securely.
---
Getting Started
The DeviceAssure JavaScript library must be included on a webpage for it to
work. It is recommended to include the library at the end of the web page.
The DeviceAssure library can be used in three different ways: ["Client to Server"](#client-to-server-usage), ["Server to Server"](#server-to-server-usage) and ["IMEI Corroboration"](#imei-corroboration).
There are a number of methods exposed in the DeviceAssure library. However, the `.load` method is the recommended method to use. The remaining methods have been deprecated and should no longer be used. These will be removed in a future release.
Property | Description
------------ | -------------------------------------------------------------------------------------------------------------------
`.load` | Entrypoint method for the library. Please see the setup guides below for more details.
`.check` | [Deprecated, use `load`] Please see the Migration Guide included in our bundle for help moving to the new `.load` method above.
`.checkIMEI` | [Deprecated, use `load`] Please see the Migration Guide included in our bundle for help moving to the new `.load` method above.
`.getData` | [Deprecated, use `load`] Please see the Migration Guide included in our bundle for help moving to the new `.load` method above.
Client to Server
For this option the data is collected by the library and automatically sent to the DeviceAssure API for device verification.
There are two recommended ways to use the library in this scenario. The first is ["Page Load Setup"](#page-load-setup) and the second is upon a ["User Event"](#user-event-setup) e.g. a click of a button the `.check` method is called directly.
Page Load Setup
The following is a list of configurations that can be set on the DeviceAssure library for the page load setup.
| Property | Type | Default | Description |
|------------------|--------------------------|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `serverToServer` | Boolean | `false` | Enable server to server mode. This will disable the automatic validation to the DeviceAssure service and manual data collection can then occur. |
| `imei` | String | 'undefined' | Provide an IMEI for use as another identifier for device verification. When `imei` is present it must not be defined with an IMEI value. |
| `tags` | List