Skip to main content
Sessions are the foundation of Uplink’s security and connection model. Understanding how to create, manage, and secure sessions is essential for production use.

What is a session?

A session is an authenticated connection that allows your JavaScript code to communicate with mobile devices. Sessions are created programmatically using your OAuth client credentials and enable secure, real-time bidirectional communication.

Creating sessions

Sessions are created programmatically in your code using your OAuth client credentials. The session is automatically scoped to the project the client belongs to.
1

Get your credentials

Create an OAuth client in Uplink Console and copy its client ID and secret. See Authentication for the full walkthrough.
2

Create a session in code

Use the uplink.session() method to create a session with your credentials:
3

Connect a client to the session

Create a client from your session to interact with connected devices:
4

Deliver the session to your device

The session object exposes two URLs for connecting a device. Use the one that matches your integration:
Display session.qrUrl as a QR code in your UI. When your user scans it, the Uplink Connect app opens and joins the session automatically.

The session object

uplink.session() and uplink.getSession() both resolve to the same shape:
Half of it is safe to hand out and half of it is credential material, so the distinction matters as soon as you persist a session or return one from an HTTP endpoint: credential and keys are optional because neither is always present: getSession() never returns credential, and keys only appears for the key types you requested via include: { ecdh: true, ecdsa: true }.
Do not return the whole session object from an API endpoint your frontend calls. Pick out qrUrl (and sessionId if your UI needs it) and leave credential and keys on the server.

Session security

Sessions are authenticated with your OAuth client credentials, which provide:
  • Project identity: Each OAuth client belongs to exactly one project — sessions created with it are scoped to that project automatically.
  • Secure communication: Encrypted connections between your code and devices
  • Access control: Manage permissions through Console settings
For how to create credentials and keep them safe, see Authentication.

Session restriction

Every session is also bound to a secret verifier, so that holding a session’s URL is not enough to drive it. When you create a session, the SDK derives a challenge from the verifier and sends only the challenge to Uplink — the verifier itself never leaves your process. When a client connects, it presents the verifier as its credential. A client that presents the matching credential can discover paired devices and open connections to them. A client that does not still connects, but device discovery and connection setup are blocked for it. You do not opt in to this. If you do not supply a verifier, uplink.session() generates one for you, and either way it comes back on the session as credential:
Passing restrict: { verifier } does not turn restriction on. It only replaces the generated value with one you chose, so you can reproduce it later:
In the scripts above there is nothing to do: uplink.client.fromSession() reads credential off the session object and passes it along for you. It only becomes something you manage when you connect from a different runtime than the one that created the session.

Reconnecting from another runtime

uplink.getSession() refetches a session you created earlier — a fresh sessionUrl, the qrUrl, and optionally the keys. It never returns credential. Uplink stores only the challenge, so it cannot give the verifier back to you even in principle. That leaves two ways to reconnect, both of which come down to having the verifier on hand. Persist the credential you were given. Store session.credential alongside session.sessionId when you create the session, then merge it back in before connecting:
Or choose your own verifier. If you would rather not persist a generated value, supply the verifier at create time and read it from the same place in both runtimes — then you only persist the sessionId:
The verifier lives in your configuration, the same way your client secret does. When choosing one:
  • Treat it like a password. Anyone who has it, plus the session’s URL, can drive the session.
  • Use a high-entropy value — a UUID or a random 32-byte string — not a guessable name.
  • Uplink cannot recover it for you. If you lose the verifier for a session you intended to reconnect to, create a new session.
  • A verifier belongs to one session. Reusing one across sessions gains you nothing and widens the blast radius if it leaks.
Keep the verifier out of anything you show a user. session.qrUrl is the only URL a user ever needs — the credential is strictly between your code and Uplink.

Session lifecycle

Connection

When you connect to a session, the client establishes a WebSocket connection to the Uplink relay server:

Active session

During an active session:
  • Devices can connect and disconnect
  • Browsers can be launched and managed
  • Commands are sent in real-time
  • Events are emitted for device state changes

Closing a session

Always close the client when you’re done to properly clean up resources:
Create and destroy sessions as needed for your use case. For automated testing, create a new session for each test run and close it when complete.

Session expiration

Sessions end when:
  • The connection is closed by the client (client.close())
  • The session is terminated in the Console
  • The OAuth client used to create the session is disabled or deleted
  • Network connectivity is lost
When a session expires, all connected devices are disconnected and browsers are closed. Plan for graceful handling of session expiration in long-running automations.

Multi-session patterns

Load distribution

For high-volume automation, distribute load across multiple sessions:

Next steps

Device management

Learn how to manage devices in sessions

Client API

Explore the Client API reference