Authentication, connection, and pairing
Pipedash lets a device run its own host or connect to a Pipedash host on another computer. A pairing code enrolls a new device and gives it a device token. Provider sign-in is a separate flow that gives the host access to an external provider account. For the wider security model, see Secure connectivity and credentials.
Connection lifecycle
The connection lifecycle moves from a user choice to an active local or remote session. The React entry screens collect the choice and show the result. Desktop commands then start the local core or create the remote session.
flowchart TD
A[Open Pipedash] --> B{Choose where to run}
B -->|This device| C[Create or load local setup]
B -->|A server or computer| D[Enter address and pairing code]
D --> E[Claim device on host]
E --> F[Save device token]
F --> G[Open authenticated session]
C --> H[Use local core]
G --> I[Use remote host]
Run modes
The app has three connection modes: unset, standalone, and client. Unset shows onboarding. Standalone uses the local core. Client uses a paired device identity to reach a server or desktop host. The selected mode also decides whether the shared service uses local commands or remote API requests. src/…/connection.ts• L8-34 src/…/service.ts• L1-10
References: src/…/WelcomeScreen.tsx• L66-103 src/…/connection.ts• L8-40 crates/…/mod.rs• L523-549
Setup flow
The setup flow prepares a standalone host before it can serve provider data. It first loads the current storage, vault, and default-directory state. A load failure shows a retry state and does not expose a partial setup form. src/…/SetupWizard.tsx• L11-69 src/…/SetupWizard.test.ts• L129-148
The user can choose local SQLite storage or desktop PostgreSQL storage. Desktop setup also creates or confirms the vault password unless the configured environment variable can unlock it. Mobile setup keeps data in device storage and uses the platform secure store for provider tokens. The wizard checks the draft as it changes, blocks progress while the current check is pending, and checks it again before saving. src/…/StorageStep.tsx• L50-98 src/…/usePreparedSetup.ts• L19-39 src/…/useSetupSubmission.ts• L48-87
When an existing configuration changes its data location, the wizard offers a transfer choice. Transfer keeps providers, tokens, and history available in the new location. A fresh start leaves that data in the old location. The wizard validates the draft before it saves the configuration, then shows migration results when a transfer runs. A local core may need a reload or restart before it uses the new database. src/…/TransferStep.tsx• L20-38 src/…/useSetupSubmission.ts• L63-84 src/…/SuccessStep.tsx• L35-117
The wizard uses the same broad stages across desktop and mobile. The compact mobile flow can apply a first-run setup directly after storage checks. An existing mobile setup still exposes transfer when a location change needs it. src/…/SetupWizardSession.tsx• L41-95 src/…/SetupWizardLayout.tsx• L90-121
References: src/…/SetupWizard.tsx• L11-69 src/…/SetupWizard.test.ts• L129-225 src/…/SetupWizardSession.tsx• L41-181 src/…/StorageStep.tsx• L50-98 src/…/TransferStep.tsx• L20-38 src/…/SuccessStep.tsx• L35-117 src/…/usePreparedSetup.ts• L19-39 src/…/useSetupSubmission.ts• L48-87
Configuration recovery
Configuration recovery is separate from first-run setup. When the saved configuration cannot load, the app shows the reported errors and the configuration-file path when known. The user must fix the configuration and retry before the app continues. src/…/ConfigErrorScreen.tsx• L8-43
References: src/…/ConfigErrorScreen.tsx• L14-41 src/…/SetupWizard.tsx• L33-69
Remote connection setup
The connection screen accepts a host address with a separate pairing code or a complete pairing link. On mobile it can read the link from a QR code. The same form can pair an alert-only host, so a device may keep local pipelines while receiving alerts from another host. Plain HTTP requires an explicit private-network choice. src/…/ConnectServerScreen.tsx• L16-69 src/…/ConnectServerForm.tsx• L83-121
The form treats a pipedash:// value as a complete link, so it does not ask for a second code. Mobile users can scan a pairing QR code or enter the address and code when camera access is unavailable. A successful full connection shows a dashboard action. An alert-only connection keeps the local app in place and sends the user to notification settings. src/…/ConnectServerForm.tsx• L122-173 src/…/ConnectServerDone.tsx• L10-52
The form clears private-network consent when the address changes. If the host rejects unencrypted access, it asks for consent for that exact address and does not reuse the choice for another host. src/…/ConnectServerForm.tsx• L97-120 src/…/ConnectServerForm.test.tsx• L86-109
References: src/…/ConnectServerScreen.tsx• L16-69 src/…/ConnectServerForm.tsx• L83-121 src/…/ConnectServerForm.tsx• L122-185 src/…/ConnectServerForm.test.tsx• L64-130 src/…/ConnectServerFields.tsx• L35-89 src/…/ConnectServerDone.tsx• L16-52
Revoked access
The host can remove a paired device at any time. The remote session treats a failed device authentication or a removal response as revoked access. It stops remote work and the React gate asks the user to set up the connection again. Temporary network loss instead shows an unreachable-host screen, where the user can retry or disconnect without removing the saved device. src/…/ServerAccessGate.tsx• L16-55 src/…/HostUnreachableScreen.tsx• L18-61 crates/…/session.rs• L446-470
References: src/…/ServerAccessGate.tsx• L16-81 src/…/HostUnreachableScreen.tsx• L18-89 crates/…/session.rs• L185-187 crates/…/session.rs• L527-583
Pairing lifecycle
Pairing is the enrollment path for a device that does not yet have a host token. The host creates a short-lived offer. The new device claims it over the WebSocket connection. The host returns a device identity and token, then the device uses that token for later sessions.
Pairing offers
The host creates an offer through POST /api/v1/devices/pairing. The response contains a normalized server URL, an eight-character code, a pipedash:// link, an expiry time, and QR markup. Desktop sharing exposes the same offer through its pairing-code command. Codes remain open for five minutes, and the host limits the number of open codes. crates/…/devices.rs• L86-103 crates/…/pairing.rs• L25-88
References: crates/…/devices.rs• L54-56 crates/…/devices.rs• L130-134 crates/…/pairing_codes.rs• L26-66 crates/…/mod.rs• L389-405
Pairing claims
The new device opens the host WebSocket and sends its code, display name, and platform. The host validates the device details and consumes the code before it creates the device record. A successful claim returns an authenticated response with the device ID and a new token. The code cannot be claimed again. crates/…/session.rs• L84-106 crates/…/ws.rs• L400-444
References: crates/…/pairing.rs• L113-172 crates/…/ws.rs• L299-323 crates/…/ws.rs• L400-444 crates/…/lib.rs• L369-390
Device credentials
The host stores a hash of the device token and uses the token to identify later requests. Desktop stores the token in the platform keychain. It stores the host address, device ID, host kind, and display name as separate connection metadata. This separation lets the app reconnect without putting the token in its connection settings file. crates/…/pairing.rs• L175-215 crates/…/store.rs• L26-108
References: crates/…/pairing.rs• L185-215 crates/…/store.rs• L40-49 crates/…/store.rs• L88-108 crates/…/mod.rs• L738-764
Pairing management
The host exposes GET /api/v1/devices to list paired devices and DELETE /api/v1/devices/{id} to revoke one. The React device settings use these operations to show current devices and remove access. A device token is accepted for normal data access, but host-managed actions remain on the host. src/…/useConnectionQueries.ts• L57-83 crates/…/devices.rs• L105-147
References: src/…/api.ts• L933-943 crates/…/devices.rs• L86-147 crates/…/lib.rs• L131-178 crates/…/lib.rs• L217-242
Session authentication
After enrollment, the client authenticates each WebSocket session with its saved token. The host returns the host kind, host name, and device identity before it accepts requests or forwards events. A lost socket causes reconnect attempts. A rejected device token changes the session to removed instead of causing an endless retry.
WebSocket sessions
The remote desktop session sends either an auth message with a saved device token or a claim message with a pairing code. After auth-ok, it sends request frames over the same session. The host can also accept an operator token for host administration. crates/…/session.rs• L291-327 crates/…/ws.rs• L325-398
References: crates/…/session.rs• L84-116 crates/…/session.rs• L291-327 crates/…/ws.rs• L299-398
Web API authentication
The web host protects most API routes with a bearer token. It accepts either the host operator token or a paired device token. Setup status, health, vault status, sign-in endpoints, and the WebSocket entry point have separate access rules so a client can start or inspect the required lifecycle. crates/…/lib.rs• L131-179
References: crates/…/lib.rs• L56-66 crates/…/lib.rs• L131-179 crates/…/mod.rs• L31-52
Provider sign-in lifecycle
Provider sign-in authorizes an external service for a provider. It does not pair the device with a Pipedash host. The host owns the flow and stores the resulting provider credential behind the vault described in Credential and vault handling.
Authorization flows
The React provider experience starts a flow and receives an authorization URL and flow ID. Web clients open the URL in a new browser tab. Desktop opens it in the system browser. Mobile opens a native authentication session. The host watches for the redirect and exchanges the authorization result for a provider credential. src/…/useSignInQueries.ts• L14-60 src/…/api.ts• L400-447 crates/…/sign_in.rs• L27-131
References: src/…/api.ts• L400-447 crates/…/sign_in.rs• L27-131 crates/…/sign_in_service.rs• L108-151 crates/…/sign_in_service.rs• L209-299
Sign-in states
Each provider flow has a pending, completed, failed, or expired state. The UI polls while the flow is pending. A matching redirect completes the flow. A wrong redirect, missing authorization code, failed provider response, timeout, or cancellation ends the flow without granting provider access. Completed credentials can be renewed before use when the provider supports refresh. crates/…/sign_in_service.rs• L192-207 crates/…/sign_in_service.rs• L302-356
References: src/…/useSignInQueries.ts• L14-25 crates/…/sign_in_service.rs• L38-46 crates/…/sign_in_service.rs• L192-261 crates/…/sign_in_service.rs• L318-356
Web sign-in endpoints
The web host exposes POST /api/v1/sign-in to start a flow, GET /api/v1/sign-in/{id} to read its status, POST /api/v1/sign-in/{id}/complete to submit a redirect address, and DELETE /api/v1/sign-in/{id} to cancel it. Web starts mark the flow as manual because the browser may need the user to paste the full redirect address. crates/…/sign_in.rs• L24-80
References: crates/…/sign_in.rs• L36-80 src/…/api.ts• L400-447 src/…/useSignInQueries.ts• L28-60
Change checklist
When these files or sections are changed, remember to consider these:
- Keep pairing-link parsing aligned with the address and code fields in the React connection screen.
- Keep the pairing code lifetime and one-time claim behavior aligned between the offer endpoint, WebSocket claim, and desktop client.
- Keep the device token response aligned with keychain storage and the host-side token hash lookup.
- Keep connection status, unreachable-host retry behavior, and revoked-access events aligned with the React screens and remote reconnect behavior.
- Keep private-network consent tied to the exact submitted address and reset it when the address changes.
- Keep setup draft preparation aligned with the fields shown by the wizard and with the final apply request.
- Keep setup completion aligned with local core startup so a new standalone host is not shown as ready before its core is usable.
- Keep migration results and restart or reload actions aligned with the active local database.
- Keep provider sign-in status names aligned across the host service, web routes, React polling, and desktop commands.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Pairing code expires or is already used | The device cannot enroll | Create a new code; offers last five minutes and are single-use |
| Host address is invalid or uses public plain HTTP | The client does not send pairing data | Use an HTTP(S) host address and allow plain HTTP only for a trusted private network |
| Device token is missing, rejected, or revoked | The remote session stops and the UI asks for setup again | Re-pair the device rather than retrying the old token |
| Sharing is off or the host has no usable network | The host cannot create a pairing offer | Enable sharing and restore network access before creating the code |
| Provider redirect belongs to another flow | The sign-in stays pending or fails without a credential | Use the redirect from the current browser flow and complete it before expiry |
| Setup storage state cannot load | The wizard shows an error and does not offer an incomplete first-run form | Retry the state read before selecting storage settings |
| Setup draft check is still running or fails | The wizard cannot safely continue or save the draft | Wait for the current check or retry it after correcting the storage settings |
| Storage changes without data transfer | Existing providers, credentials, and history remain in the old location | Select data transfer when the existing host data must remain available |
| A migrated local database is not reloaded | The running core continues to use the previous database | Reload or restart the app after setup completes |
| Private-network consent was given for a different address | The next connection may be blocked or receive the wrong trust choice | Change the address and give consent again only for the current host |
Key files
| File | Why to read it |
|---|---|
| src/…/WelcomeScreen.tsx | Shows the user choice between local and remote operation. |
| src/…/EntryScreen.tsx | Provides the shared connection entry surface for desktop and mobile web flows. |
| src/…/ConnectServerScreen.tsx | Selects normal server connection or alert-only connection and the platform layout. |
| src/…/ConnectServerForm.tsx | Connects address, pairing-link, QR, alert-host, and private HTTP choices to the pairing service. |
| src/…/ConnectServerFields.tsx | Shows the address, code, and private-network consent contract. |
| src/…/ConnectServerDone.tsx | Shows the different outcomes for a full connection and an alert-only connection. |
| src/…/ConnectServerForm.test.tsx | Defines the connection form guarantees for validation and address-bound consent. |
| src/…/ServerAccessGate.tsx | Shows how revoked access blocks the remote app and starts setup again. |
| src/…/HostUnreachableScreen.tsx | Shows the separate retry and disconnect path for temporary host loss. |
| src/…/ConfigErrorScreen.tsx | Shows configuration recovery when the saved configuration cannot load. |
| src/…/SetupWizard.tsx | Loads the setup state and separates initial loading errors from the editable wizard. |
| src/…/SetupWizardSession.tsx | Coordinates storage, transfer, confirmation, save, and success stages. |
| src/…/StorageStep.tsx | Shows the local or desktop storage choices and vault setup. |
| src/…/TransferStep.tsx | Shows how existing provider data can move to the new storage location. |
| src/…/usePreparedSetup.ts | Checks the current setup draft before the user can continue. |
| src/…/useSetupSubmission.ts | Rechecks and applies the setup draft, then returns migration results. |
| src/…/SuccessStep.tsx | Shows post-save migration results, vault reminders, and reload needs. |
| crates/…/pairing.rs | Defines the pairing offer returned to a client. |
| crates/…/pairing_codes.rs | Defines pairing-code lifetime and one-time use. |
| crates/…/ws.rs | Defines host-side claim and session authentication. |
| crates/…/mod.rs | Connects the desktop UI to pairing, token storage, and reconnect behavior. |
| crates/…/session.rs | Shows the remote handshake, request session, and revoked-access behavior. |
| crates/…/devices.rs | Defines pairing-code, device-list, and device-revocation endpoints. |
| crates/…/sign_in_service.rs | Defines the provider authorization state and credential handoff. |
| crates/…/sign_in.rs | Defines the web provider sign-in endpoints. |
| crates/…/sign_in.rs | Defines desktop browser and mobile native sign-in handoff. |