When to use device connection
Use this flow when:- The journey includes tasks that require device-specific capabilities such as camera and biometrics.
- You want end users to complete verification steps on their own mobile device.
- Your integration involves a handoff between a backend system and a user-facing application.
How it works
The device connection flow involves two API calls:- Create a connect token: Your backend calls
/journey/device/startto generate a short-lived connect token. - Exchange for end-user token: The end user’s device calls
/journey/device/connectwith the connect token to receive an end-user token.
Prerequisites
Before connecting a device, you need:- An active journey instance: You must have already started a journey and have the
instanceId - Access token: A valid access token from the Authenticate step
Step 1: Create a connect token
Call the/journey/device/start endpoint from your backend to generate a connect token.
cURL
Response
The response contains the connect token:JSON
Step 2: Pass the token to the end user
After receiving the connect token, pass it to the end user’s device. Common methods include:- QR code: Display a QR code containing the token or a URL with the token.
- Deep link: Send a link that opens your mobile app with the token.
- SMS/Email: Send the token or a connection URL directly to the user.
Step 3: Connect the end user device
From the end user’s device, call/journey/device/connect to exchange the connect token for an end-user token.
cURL
The connect token obtained from the
/journey/device/start endpoint must also be used as the Bearer token in the Authorization header for the /journey/device/connect request.Response
The response contains the end-user token:JSON
Step 4: Use the end-user token
The end-user token is a JWT that the device uses to authenticate subsequent API calls. Include it in theAuthorization header when completing tasks:
cURL
Error handling
Common error codes when connecting an end user device, their causes, and solutions:| Error code | Cause | Solution |
|---|---|---|
| 400 | Connect token already used. | The connect token has already been used and deleted. Generate a new connect token. |
| 401 | Connect token expired or invalid. | Generate a new connect token. |
| 403 | Device type not allowed by scope. | Check the scope parameter when creating the connect token. |
| 404 | Journey instance not found. | Verify the instanceId is correct and the journey is still active. |
The connect token can only be used once. After a device successfully exchanges the connect token for an end-user token, the connect token is immediately invalidated and deleted from the system.If another device, or the same device attempts to use the same connect token again, then the API returns an error because the token no longer exists.What happens when a different device tries to connect using an already-used token:
- Device A uses the connect token and successfully receives an end-user token.
- The connect token is deleted from the system.
- Device B tries to use the same connect token.
- The API returns an error because the token no longer exists.
API reference
- Create connect token – Full API reference for
/journey/device/start - Connect end user device – Full API reference for
/journey/device/connect