Overview
WebSocket connections require an SDK token for authentication. The token is validated on connection and contains user and tenant context.This page is for connecting to the WebSocket directly. If you’re using the
SDK, it handles all of this for you. For how tokens are minted in the first
place, see Authentication & tokens.
Connection with Token
Using Sec-WebSocket-Protocol (browsers)
Browsers cannot set custom headers on WebSocket. Pass the token as a subprotocol (from your backend):Using Authorization Header (Node.js)
When using a WebSocket client that supports custom headers:Using Query Parameter
Token Validation
The server validates:- Token signature — Valid JWT signature
- Token expiration — Not expired (e.g. 24h lifetime)
- Token type — SDK token (e.g.
sdk_user) - App/tenant context — Valid app and tenant
Token Claims
Authentication Flow
Getting an SDK Token (Backend)
Your backend issues tokens viaPOST /api/v1/apps/:appId/tokens. See Issue SDK Token.
API key (server-to-server):
Authorization: Bearer <access_token> instead of API key headers. Return data.token to your frontend.
Error Handling
Invalid Token
1008 (Policy Violation).
Expired Token
Token Refresh Strategy
Since SDK tokens expire after 15 minutes, implement token refresh:Using the SDK
Use the token from your backend only—never keys:Security Best Practices
Token Lifetime
SDK tokens are time-bound; refresh via your backend before expiry.
Use HTTPS/WSS
Always use secure connections.
Backend-only Keys
App ID, public key, and secret key stay on your backend. Frontend uses tokens only.
Don't Log Tokens
Never log tokens in production.
Next Steps
Message Types
WebSocket message types
Rooms
Room management
SDK Auth
SDK authentication
REST Auth
REST API authentication