Repository Public
1# Native client API contract (binding for backend and Swift workstreams)23Additive extension of the Claude Remote / Codex Remote server (`apps/server`, base `/api/v1`). Nothing4existing changes for browsers: cookie sessions, CSRF and Origin rules stay exactly as they are.5Team ID `3YM54G49SN`. Bundle ids: `ai.spboucher.clauderemote` (Claude instance), `ai.spboucher.codexremote`6(Codex instance); the same id is used by the macOS and the iOS app; Debug builds use the suffix `.dev`.78## 1. Apple App Site Association910`GET /.well-known/apple-app-site-association` — public, `Content-Type: application/json`, no redirect, 200:1112 {"webcredentials":{"apps":["3YM54G49SN.<bundle>","3YM54G49SN.<bundle>.dev"]},13 "applinks":{"details":[{"appIDs":[same list],"components":[{"/":"/open/*"}]}]}}1415App ids come from `CR_APPLE_APP_IDS` (comma list); default derived from the agent profile as above.16Must be deployed to production BEFORE any signed app is first launched (Apple's CDN caches misses).1718## 2. Native sessions (bearer, device-bound)1920A native session is a row of `auth_sessions` with `client_kind = 'native'` (browser rows: `'browser'`).21- Credential: `Authorization: Bearer crn_<43 base64url chars>`; only the SHA-256 is stored.22- A bearer token is accepted ONLY for `client_kind='native'` rows; the cookie ONLY for `'browser'` rows.23- Bearer requests need no CSRF token and no Origin (no ambient credential). If an `Origin` header is24 present on a bearer request it must equal the public origin, else 403 `bad_origin`.25- Every native request carries `X-CR-Client: native/<macos|ios|ipados>/<appVersion>`; native preauth POSTs26 require it plus `Content-Type: application/json` (403 `bad_client` otherwise).27- WebSocket upgrades (`/sessions/:id/stream`, `/tasks/:id/log/stream`, `/events`) accept the same bearer header.28- Access token lifetime `CR_NATIVE_TOKEN_TTL_SEC` (default 3600). An expired token answers 401 `token_expired`29 (distinct from 401 `unauthenticated` = session revoked/expired/unknown). Open WebSockets are tied to the30 session row, not the token: they survive a rotation and are closed with 4401 on revocation/expiry.31- Session lifetime: absolute 30 d (as browsers); idle `CR_NATIVE_IDLE_SEC` (default 14 d), justified by the32 device-bound key. Second factor pending: 15 min.33- All existing routes (`/auth/status`, `/auth/logout`, `/auth/devices`, projects, sessions, …) work unchanged34 with a bearer session at the same authorisation levels.3536Shared object:3738 NativeSession = { id: uuid, token: string, tokenExpiresAt: iso, expiresAt: iso, secondFactor: boolean }39 NativeDevice = { installId: uuid, name: string(1..80), platform: 'macos'|'ios'|'ipados',40 model: string(≤80), appVersion: string(≤40),41 publicKey: base64 (P-256 public key, X9.63 uncompressed 65 bytes) }4243### Endpoints (`/api/v1/native/auth/…`), same throttling and audit as the web equivalents4445| Route | Auth | Body → Response |46|---|---|---|47| `POST login` | preauth | `{username, password, totp?, device: NativeDevice}` → `{next: 'done'|'totp'|'passkey'|'enroll_second_factor', methods: {totp: bool, passkeys: number}, session: NativeSession}` (401 `invalid_credentials`, 429 `locked`) |48| `POST totp` | restricted bearer | `{code}` → `{next:'done', session}` (token rotated) |49| `POST passkey/options` | restricted bearer, or none | with a bearer: request options with `allowCredentials` (second step). Without: `{device: NativeDevice}` not needed here → options for discoverable credentials plus `challengeToken` (opaque, 5 min, single use) : response `{options: PublicKeyCredentialRequestOptionsJSON, challengeToken: string|null}` |50| `POST passkey/verify` | restricted bearer, or none | `{credential: AuthenticationResponseJSON, challengeToken?: string, device?: NativeDevice}` → `{next:'done', session}`. Without a bearer, `challengeToken` and `device` are required and a new full native session is issued (passkey with user verification on its own — same rule as the web). |51| `POST refresh/challenge` | none (token may be expired) | `{sessionId}` → `{challenge: base64url, expiresAt}` (60 s, single use; 404-free: unknown session answers a decoy challenge) |52| `POST refresh` | none | `{sessionId, signature}` → `{session}`; `signature` = base64 DER ECDSA-P256-SHA256 over the UTF-8 bytes of `cr-native-refresh:v1:<sessionId>:<challenge>`, verified against the session's device public key. Rotates the token (old one dies at once). Only for full, live sessions; failure 401 `unauthenticated` and counted by the throttle. |5354WebAuthn verification is unchanged: RP ID = host of `CR_PUBLIC_ORIGIN`, expected origin = `CR_PUBLIC_ORIGIN`55(Apple platform authenticators put `https://<rpId>` in clientDataJSON for associated apps), UV required.56Passkey registration from a native app uses the existing `/auth/passkey/register/options|verify` with a bearer.5758### Devices5960`GET /auth/devices` gains entries `kind: 'native'` (label = device name) with additive optional fields61`platform`, `model`, `appVersion`, `pushEnabled`. `DELETE /auth/devices/:id` revokes it (WebSockets closed 4401,62push token dropped). `Device.kind` becomes `'passkey'|'session'|'native'`.6364## 3. Push6566- `PUT /native/push` (full bearer) `{apnsToken: hex, environment: 'sandbox'|'production', topic: string}` → `{ok:true, configured: boolean}`67 (`topic` must be one of the instance's app ids without the team prefix). `DELETE /native/push`.68- Server sends through APNs HTTP/2 with a provider token (ES256) when `CR_APNS_KEY_FILE`, `CR_APNS_KEY_ID`,69 `CR_APNS_TEAM_ID` are set; otherwise push is reported `configured:false` and nothing is sent.70- Every `Notifier.notify` also fans out to the user's native devices. Payload:71 `{"aps":{"alert":{"title":<generic title>,"body":<body or omitted>},"sound":"default","thread-id":<kind>,"interruption-level":"time-sensitive" only for session.waiting},"cr":{"kind","link","notificationId"}}`.72 Never terminal content; `body` only when the user's `notifications.detail = 'titles'`.73 A 410/`BadDeviceToken`/`Unregistered` answer deletes the token.74- `UserSettings.notifications` gains `push: boolean` (default true).7576## 4. Summary (widgets, menu bar, Home)7778`GET /native/summary` (full) →7980 { serverTime: iso, agent: 'claude'|'codex', productName: string,81 sessions: { live: number, waiting: number, running: number, detached: number, recoverable: number },82 tasks: { running: number, queued: number, failed24h: number, succeeded24h: number },83 cluster: { nodes: number, online: number, health: Health, collectedAt: iso|null } | null,84 notificationsUnread: number }8586## 5. Deep links8788Notification `link` values are web paths (e.g. `/terminal/?s=<id>`, `/tasks/?t=<id>`); native apps map them89to their own navigation. Custom URL schemes: `clauderemote://` and `codexremote://` with the same path + query.90