Skip to content

Server to Server

For this integration method, the DeviceAssure library collects device data and makes it available to your 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.


Overview

There are five main steps to validate a device:

  1. Initialize the DeviceAssure library with the application context
  2. Call the getData() method with a callback handler to collect device data
  3. Transmit the collected data securely to your server
  4. Your server makes a request to the DeviceAssure API with the collected data and HTTP headers
  5. Validation results are returned directly to the server

Implementation

Step 1: Initialize the Library

Initialize DeviceAssure in your Application class's onCreate() method:

import android.app.Application;
import com.deviceassure.android.library.networking.DeviceAssure;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        DeviceAssure.init(this.getApplicationContext());
    }
}

Step 2: Define the Callback Interface

Create a delegate interface to handle the collected data:

import org.json.JSONObject;

public interface DeviceAssureDelegate {
    void onResponse(JSONObject json);
    void onError(String error);
}

Step 3: Create a Callback Handler

import org.json.JSONObject;
import com.deviceassure.android.library.networking.Callback;

public class DeviceAssureCallback implements Callback {

    private DeviceAssureDelegate delegate;

    public DeviceAssureCallback(DeviceAssureDelegate delegate) {
        this.delegate = delegate;
    }

    @Override
    public void taskComplete(JSONObject collectedData) {
        // The data collected from the device is passed here
        // Send it securely to your server for validation
        delegate.onResponse(collectedData);
    }

    @Override
    public void handleError(String errorStr) {
        delegate.onError(errorStr);
    }

    @Override
    public void progressUpdate(Integer percent) {
        // Track progress if needed
    }
}

Step 4: Collect Device Data

Call the getData() method from anywhere in your application:

DeviceAssure.getData(new DeviceAssureCallback(this));

Complete Example

import android.app.Application;
import android.util.Log;
import org.json.JSONObject;
import com.deviceassure.android.library.networking.DeviceAssure;

public class MyApplication extends Application implements DeviceAssureDelegate {

    private static final String TAG = "DeviceAssure";

    @Override
    public void onCreate() {
        super.onCreate();

        // Initialize the library
        DeviceAssure.init(this.getApplicationContext());

        // Collect device data
        DeviceAssure.getData(new DeviceAssureCallback(this));
    }

    @Override
    public void onResponse(JSONObject json) {
        Log.d(TAG, "Device data collected: " + json.toString());
        // Send this data to your server for validation
        sendToServer(json);
    }

    @Override
    public void onError(String error) {
        Log.e(TAG, "Collection error: " + error);
    }

    private void sendToServer(JSONObject deviceData) {
        // Implement secure transmission to your server
        // Your server will then call the DeviceAssure API
    }
}

When to Call Data Collection

The getData() method can be called from anywhere in the application, but it is recommended to call it:

  • On application install
  • On application create (onCreate())

Exception: If certain permissions are required before calling the library (e.g., to allow collection of the TAC), wait until those permissions are granted.


Server-Side Implementation

Once your server receives the collected data 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)
  • Request format and examples
  • Response handling

See Also