Integration Flow
The complete behavioral scoring flow involves your app, your backend, the SDK and the TrustVision API:
SDK version
This page uses the v1.0.1.x SDK API. On **v1.0.0.3** the server calls are the same, but the app reads the registration values from the `TSDeviceInitInfo` that `initialize()` returns and registers when `initInfo.isRegistered` is `false`. v1.0.0.3 has no `setCusUserId`, `getRegistrationStatus`, `reportRegistrationFailed` or `clearUser`, so your app keeps the `cus_user_id` and decides when to register again itself (call `clearDeviceIdentity()` for a full reset), and it does not rotate challenges. See the [SDK guides](/api-docs/behavioral-api/sdk-integration/) for each version.
Your App + SDK (device) Your Backend TrustVision API
| | |
|-- initialize(config) ----------->| (SDK generates the device |
| bootstrapKeyId + | RSA key pair on the device) |
| bootstrapPublicKey | |
| | |
|-- getRegistrationStatus() | |
| = Required(deviceId, | |
| bootstrapKeyId, encrypted | |
| device public key, ...) | |
|--- registration values --------->| |
| |--- POST /v1/register_device ->|
| |<-- customer_user_device_id ---|
|<-- customer_user_device_id ------| |
|-- markDeviceRegistered(...) | |
| | |
|-- startCollect() --- POST /v1/behavior/create_challenge ------->|
|<------------------- challenge_id, nonce, server_public_key -----|
|-- (collect) ------- POST /v1/behavior/push_event_batch -------->|
| | |
|-- finalizeCollect() | |
| = TSFinalizeResult.challengeId | |
|--- challengeId + action -------->| |
| |--- POST /v1/behavior/score -->|
| |<-- behavior_score, decision --|
- TrustVision issues a bootstrap key pair (RSA-2048) for your environment and gives you its id and public key. Pass them to the SDK as
bootstrapKeyId/bootstrapPublicKey; your backend sends the same id askey_pair_idtoregister_device. The private half never leaves TrustVision. - The SDK generates the device key pair on the device (Android Keystore, iOS Keychain) during
initialize(). The private key never leaves the device. The SDK encrypts the device public key with the bootstrap public key. - Your app asks the SDK whether registration is needed with
getRegistrationStatus(). OnRequired, it sends the returned values (deviceId,bootstrapKeyId,encryptedDevicePublicKeyPayload,encryptedSecretKey,cusUserId) to your backend. - Your backend calls
POST /v1/register_devicewith them and returnsdata.customer_user_device_idto the app. The app hands it to the SDK withmarkDeviceRegistered(true, customerUserDeviceId, cusUserId)— orreportRegistrationFailed(statusCode)on failure. - The SDK calls
POST /v1/behavior/create_challengewhen collection starts, which returns a challenge ID, nonce, and server public key. - The SDK collects behavioral data (touch, typing, sensors) and pushes batches via
POST /v1/behavior/push_event_batch. - At the action you want to score, the app calls
finalizeCollect(). Its result'schallengeIdis the session reference: send it to your backend together with the action. - Your backend calls
POST /v1/behavior/scorewith that value aschallenge_id(and optionaltransaction_data) to get the behavior score, risk level, and — when the policy check is enabled — the recommendeddecision.final_action. - On the user's first session, step 8 enrolls the behavioral baseline instead of scoring (
more_details.is_first_session: true); real scoring starts from the second session.
When to register again
getRegistrationStatus() returns Required again — and your backend must call register_device again — when:
| Trigger | Why |
|---|---|
| A different user signs in on the device | setCusUserId() was given a cus_user_id the device is not registered for |
| The user signs out | clearUser() forgets the cus_user_id, the customer_user_device_id and the registration; the device key is kept |
| The device identity is reset | clearDeviceIdentity() also deletes the device key pair, so a new one is generated |
| The app is reinstalled | Android loses the stored keys and identity; on iOS the Keychain survives, but the SDK forgets the user on the first launch of a new install |
| TrustVision rotates the bootstrap key | A new bootstrapKeyId in the config invalidates the registration |
| The device key is lost or regenerated | The registered device public key no longer matches |
After a rejected registration (any HTTP answer, reported with reportRegistrationFailed), the SDK returns CoolingDown for that cus_user_id for 10 minutes; a new sign-in (setCusUserId) clears it. Every register_device call creates a new customer_user_device record, so do not call it when the status is Registered.