Client to Server
For this integration method, the data is collected by the library and automatically sent to the DeviceAssure API for device verification. Results are returned directly to your web application via callbacks.
Note: A valid licence key is required for Client to Server integration.
Configuration Options
The following options can be passed to the DeviceAssure.load() method:
| Property | Type | Default | Description |
|---|---|---|---|
licence | String | null | Required. The licence key to use for the DeviceAssure service. |
onSuccess | Function | function() {} | Callback function called when the DeviceAssure service returns a successful response. |
onError | Function | function() {} | Callback function called when the DeviceAssure service returns an error response. |
storageType | String | local-storage | Cache storage type. See Storage Types. |
storageExpiry | Number | 1800000 | Cache validity in milliseconds. See Cache Expiry. |
imei | String | undefined | IMEI for device verification. See IMEI Corroboration. |
tags | Array | [] | Custom metadata tags. See Custom Tags. |
Callbacks
onSuccess
Called when the DeviceAssure service returns a successful validation response. The callback receives an object containing the HTTP status and the API response as a JSON string.
onSuccess: function(response) {
var result = JSON.parse(response.response);
console.log(result.result); // AUTHENTIC, NON-AUTHENTIC, etc.
console.log(result.referenceId); // Unique ID for this validation
console.log(result.reason); // Description of the result
}
onError
Called when an error occurs during validation.
onError: function(error) {
console.error('DeviceAssure error:', error);
// Handle the error appropriately
}
Page Load Setup
Validate the device automatically when the page loads:
<script type="text/javascript">
function onDeviceAssureLoad() {
DeviceAssure.load({
licence: '<LICENCE_KEY>',
storageType: 'local-storage',
tags: [
{ key: 'page-identifier', value: 'login' },
{ key: 'action', value: 'on-page-load' },
],
onSuccess: function(response) {
var result = JSON.parse(response.response);
console.log('Validation successful', result);
// Check result.result for AUTHENTIC, NON-AUTHENTIC, etc.
},
onError: function(error) {
console.log('Validation error', error);
}
});
}
</script>
<script src="<path/to/deviceAssure.min.js>" defer async onload="onDeviceAssureLoad()"></script>
A working example can be found in SampleApplication/src/pages/client-to-server/on-page-load in the Web library package.
User Event Setup
Validate the device when triggered by a user action (e.g., button click, form submission):
<script src="<path/to/deviceAssure.min.js>" async defer></script>
<script type="text/javascript">
$('.example-submit-button').on('click', function() {
DeviceAssure.load({
licence: '<LICENCE_KEY>',
storageType: 'none',
tags: [
{ key: 'page-identifier', value: 'login' },
{ key: 'action', value: 'on-submit-clicked' },
],
onSuccess: function(response) {
var result = JSON.parse(response.response);
console.log('Validation successful', result);
},
onError: function(error) {
console.log('Validation error', error);
}
});
});
</script>
A working example can be found in SampleApplication/src/pages/client-to-server/on-event in the Web library package.
With IMEI
Include an IMEI for additional device verification. See IMEI Corroboration for requirements and best practices.
<script src="<path/to/deviceAssure.min.js>" type="text/javascript" async defer></script>
<script type="text/javascript">
$('.example-submit-button').on('click', function() {
DeviceAssure.load({
licence: '<LICENCE_KEY>',
imei: '<IMEI>',
storageType: 'none',
onSuccess: function(response) {
var result = JSON.parse(response.response);
console.log('Validation successful', result);
// Check result.deviceCheck for GSMA blocklist status
},
onError: function(error) {
console.log('Validation error', error);
}
});
});
</script>
A working example can be found in SampleApplication/src/pages/client-to-server/imei in the Web library package.
See Also
- Server to Server - Validate via your backend server instead
- How It Works - Client to Server and Server to Server models
- Configuration Options - Storage, caching, tags, and IMEI options
- API Responses - Understanding validation results and classifications