SDK Authentication
Tie an installed copy of your app to one Sonar user without putting your API key in the app.
Your API key stays on your backend. When the SDK needs to act for a user, it asks your backend, which vouches for the signed-in user by creating a client token. The SDK trades that token for its own session: a credential for one user, on one installation of one app, in one environment, that can only send that user’s health data.
- 1 Your app configure creates an installation ID
- 2 Your app → Your backend Your token function: app ID + installation ID
- 3 Your backend → Sonar POST /v1/users/{id}/sdk-sessions
- 4 Sonar → Your backend client_token, single use, 5 minutes
- 5 Your backend → Your app client_token
- 6 Your app → Sonar Exchange the token for a session
- 7 Sonar → Your app Session, kept in secure storage
- 8 Your app → Sonar Health data
After the handshake, the SDK renews its session with Sonar by itself. Your backend is only asked again when a session has ended. An SDK session cannot read data through the API, manage users, or change your organization; your backend does all of that with its API key.
Register a Mobile App
Each app build that uses the SDK needs a registration in Atlas, under Developers → Apps → Mobile apps, with its platform and its bundle ID or package name. Atlas gives it an app ID, such as app_Qm3t8Vx1LmN0aB7cD9eF2g, which goes into the build. The app ID identifies the app; it is not a secret. What protects your users’ data is your backend deciding who gets a client token.
Registrations belong to one environment, so you register once in Sandbox and once in Live, and each gets its own app ID. A React Native app registers once per platform, because the iOS and Android builds have different identifiers. The platform decides the provider: Apple Health for iOS, and Health Connect and Samsung Health for Android through the Android SDK, in early access.
Disabling an app in Atlas signs out every phone using it and stops their syncing. New client tokens for it fail with 403 sdk_application_disabled until you enable it again. Data already in Sonar is kept.
Installations and Sessions
The SDK creates a random installation ID the first time it runs. It is not a hardware identifier and grants no access on its own. It survives sign-out; reinstalling the app creates a new one.
An installation belongs to one user at a time. When a different user signs in, authenticate notices the new userId and signs the previous user out first. The SDK keeps userId on the phone only as a hash and never sends it to Sonar. If the phone was offline when it signed out, Sonar still holds the old session, and a token for another user returns 409 installation_in_use until that session expires or your backend revokes it.
A user can have one session per phone, but only one installation holds their Apple Health connection. If they connect on a second phone, that phone takes over, and the first one learns it is disconnected the next time it talks to Sonar.
Create a Client Token
/v1/users/{id}/sdk-sessionsCreates a pending SDK session and its client token, or a new client token for an existing installation.
Parameters and shapes
Path parameters
id- string (uuid) required
Request body: CreateSDKSessionRequest
app_id- string required
installation_id- string (uuid) required
Response 201: SDKBootstrap
session_id- string (uuid) required
client_token- string required
expires_at- string (date-time) required
Your token route calls this with the app ID and installation ID the SDK passed to your token function:
POST /v1/users/{id}/sdk-sessions
Authorization: Bearer $SONAR_API_KEY
Idempotency-Key: 88232d5b-f45e-4d12-b21a-643ab913b8e2
Content-Type: application/json{
"app_id": "app_Qm3t8Vx1LmN0aB7cD9eF2g",
"installation_id": "0d37df84-4a4e-4a89-a02e-e0b18203a146"
}{
"session_id": "5da61ca4-b8cb-4acf-a5cd-e90b23804e02",
"client_token": "sonar_sdk_us_init_sandbox_...",
"expires_at": "2026-09-14T14:30:00.000Z"
}A new installation returns 201 Created; a new token for an existing session, or a replay, returns 200 OK. Return client_token only to the signed-in user it belongs to, never log it, and treat its value as opaque. expires_at is the deadline to exchange it, five minutes away. It is not the session’s expiry.
A new token never interrupts a session that still works: the old session carries on until the SDK exchanges the new token, and each new token cancels any earlier one for that installation that was not exchanged.
| Status | Code | Meaning |
|---|---|---|
400 |
invalid_idempotency_key |
The Idempotency-Key header is missing or not a UUID |
400 |
invalid_body |
The body is not {app_id, installation_id}, or installation_id is not a UUID |
403 |
sdk_application_disabled |
The app is disabled in Atlas |
404 |
not_found |
The user or the app ID does not exist in this API key’s environment |
409 |
installation_in_use |
This installation has a session for another user |
409 |
idempotency_conflict |
This Idempotency-Key was used with a different body |
409 |
idempotency_expired |
This Idempotency-Key can no longer be replayed |
Retry a Client-Token Request
Create a new Idempotency-Key for each request. If your backend gets no answer, retry with the same key and body, and Sonar returns the same client token instead of making another. A replay works for 24 hours and only until the token is exchanged; after that the key returns 409 idempotency_expired, and you start over with a new one. Keys belong to the API key that sent them.
How Long Sessions Last
| Credential | Lasts | Then |
|---|---|---|
| Client token | 5 minutes, single use | Your backend creates a new one |
| Session | 30 days without use, 180 days at most | The SDK asks your token function for a new client token |
While the app runs, the SDK renews its session on its own, and each renewal restarts the 30-day window, up to the 180-day limit. Sonar sends the expiry with every credential, so never hard-code these durations or schedule refreshes yourself.
A session also ends when the app calls signOut(), when your backend revokes it, when you delete the Sonar user, or when you disable the app in Atlas. Rotating or deleting the API key that created it does not end it, and neither does disconnecting Apple Health.
When a session expires or your backend revokes it, the SDK calls your token function for a new client token, so the user notices nothing. When you delete the user, the SDK clears everything it held for them instead. It can only do that while the function is registered, which is why the app calls authenticate at every launch. Call authenticate alone: signing out first would end a working session for nothing. If your own sign-in has expired too, the SDK reports reauthorization_required and waits for the next authenticate. A network failure or a brief Sonar outage never ends a valid session. The SDK’s session status shows each of these to your app.
Manage Sessions From Your Backend
Management endpoints never return client, access, or refresh tokens, only installation details:
{
"id": "5da61ca4-b8cb-4acf-a5cd-e90b23804e02",
"app_id": "app_Qm3t8Vx1LmN0aB7cD9eF2g",
"installation_id": "0d37df84-4a4e-4a89-a02e-e0b18203a146",
"platform": "ios",
"providers": ["apple_health"],
"status": "active",
"created_at": "2026-09-14T09:30:00.000Z",
"activated_at": "2026-09-14T09:30:03.000Z",
"last_refreshed_at": "2026-09-14T12:40:00.000Z",
"expires_at": "2026-10-14T12:40:00.000Z"
}| Field | Meaning |
|---|---|
id |
Session ID, the session_id from the create response. Not a credential |
app_id |
The registered app |
installation_id |
The random ID the SDK created |
platform |
ios or android |
providers |
Providers the app registration allows |
status |
pending until the client token is exchanged, then active |
created_at |
When Sonar created the session |
activated_at |
First successful exchange, or null while pending |
last_refreshed_at |
Last exchange or renewal, or null while pending |
expires_at |
For a pending session, the token’s exchange deadline. For an active one, 30 days after the last renewal, capped at 180 days after creation |
List a User’s Sessions
/v1/users/{id}/sdk-sessionsLists the user’s pending and active sessions, newest first, in a sessions array. Expired and revoked sessions are left out. The list is not paginated.
Parameters and shapes
Path parameters
id- string (uuid) required
Response 200: SDKSessionList
sessions- SDKSession[] required
SDKSession
id- string (uuid) required
app_id- string required
installation_id- string (uuid) required
platform- string required one of ios, android
providers- string[] required
status- string required one of pending, active
created_at- string (date-time) required
activated_at- string (date-time) or null required
last_refreshed_at- string (date-time) or null required
expires_at- string (date-time) required
Revoke a Session
/v1/users/{id}/sdk-sessions/{session_id}Ends one installation’s session and cancels its tokens at once. Returns 204 No Content, also when the session was already revoked, and 404 not_found for a session that does not exist or belongs to another user.
Parameters and shapes
Path parameters
id- string (uuid) required
session_id- string (uuid) required
Response 204
Revoking touches only that installation: it does not disconnect Apple Health, delete data, or affect the user’s other phones. To remove a connection and its data, the app calls disconnect. If the app is still running, the SDK notices at its next request and asks your token function for a new client token straight away.
Blocking a lost phone
To keep an installation out for good, your token route must also refuse its installation_id. Otherwise the SDK simply signs in again through your normal route.
Sonar