Server to Server
For this integration method, the device data is collected by the library and made available to your web application. Your application then sends this data to your backend server, which makes the validation request to the DeviceAssure API.
This approach is useful when you want to:
- Keep your licence key secure on the server side
- Integrate validation into existing server-side workflows
- Have full control over when and how validation requests are made
Note: A licence key is not required on the client side. The licence key must be provided when your server calls the DeviceAssure API.
Configuration Options
The following options can be passed to the DeviceAssure.load() method:
| Property | Type | Default | Description |
|---|---|---|---|
serverToServer | Boolean | false | Required. Set to true to enable Server to Server mode. |
onSuccess | Function | function() {} | Required. Callback function that receives the collected device payload. |
onError | Function | function() {} | Callback function called when data collection fails. |
storageType | String | local-storage | Cache storage type. Typically none for S2S. See Storage Types. |
imei | String | undefined | IMEI to include in payload. See IMEI Corroboration. |
tags | Array | [] | Custom metadata tags. See Custom Tags. |
The Payload
When using Server to Server mode, the onSuccess callback receives a payload object containing all collected device data. This payload must be sent to your server in its entirety, unmodified.
| Parameter | Type | Description |
|---|---|---|
payload | Object | The complete device data collection. Send this to your server for validation. |
Callbacks
onSuccess
Called when data collection completes successfully. Receives the payload to send to your server.
onSuccess: function(payload) {
// payload contains collected device data
// Send this to your server for validation
fetch('/api/validate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
}
onError
Called when an error occurs during data collection.
onError: function(error) {
console.error('DeviceAssure error:', error);
// Handle the error appropriately
}
Page Load Setup
Collect device data automatically when the page loads:
<script type="text/javascript">
function onDeviceAssureLoad() {
DeviceAssure.load({
serverToServer: true,
storageType: 'none',
tags: [
{ key: 'page-identifier', value: 'login' },
{ key: 'action', value: 'on-page-load' },
],
onSuccess: function(payload) {
console.log('Device data collected', payload);
// Send payload to your server for validation
sendToServer(payload);
},
onError: function(error) {
console.log('Collection error', error);
}
});
}
function sendToServer(payload) {
fetch('/api/validate-device', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
}
</script>
<script src="<path/to/deviceAssure.min.js>" defer async onload="onDeviceAssureLoad()"></script>
A working example can be found in SampleApplication/src/pages/server-to-server/s2s in the Web library package.
User Event Setup
Collect device data when triggered by a user action:
<script src="<path/to/deviceAssure.min.js>" type="text/javascript" defer async></script>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', function() {
$('#submit-button').on('click', function() {
DeviceAssure.load({
serverToServer: true,
storageType: 'none',
tags: [
{ key: 'page-identifier', value: 'checkout' },
{ key: 'action', value: 'on-submit' },
],
onSuccess: function(payload) {
console.log('Device data collected', payload);
// Send payload to your server for validation
},
onError: function(error) {
console.log('Collection error', error);
}
});
return false;
});
});
</script>
A working example can be found in SampleApplication/src/pages/server-to-server/s2s-event in the Web library package.
With IMEI
Include an IMEI in the collected payload for server-side validation. 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({
serverToServer: true,
imei: '<IMEI>',
storageType: 'none',
onSuccess: function(payload) {
console.log('Payload with IMEI ready', payload);
// Send to your server for validation
},
onError: function(error) {
console.log('Collection error', error);
}
});
});
</script>
A working example can be found in SampleApplication/src/pages/server-to-server/imei-s2s in the Web library package.
Server-Side Implementation
Once your server receives the payload from the client, it must call the DeviceAssure REST API. See the Server to Server API documentation for:
- API endpoint URLs
- Required HTTP headers (DV-Client-IP, DV-User-Agent, etc.)
- Additional recommended headers for request tracing and reliability
- Request format and examples
- Response handling
See Also
- Client to Server - Direct validation from the browser
- How It Works - Client to Server and Server to Server models
- Configuration Options - Storage, caching, tags, and IMEI options
- Server to Server API - Backend API implementation details