Skip to content

Decide whether a session may start

POST
/auth
curl --request POST \
--url 'https://switchboard.mux.global/auth?jwt=example&jwt=<jwt>' \
--header 'Content-Type: application/json' \
--data '{ "id": "example", "event": "connect", "transport": "quic", "path": "acme/room/42", "query": "jwt=eyJhbGciOiJIUzI1NiIs...", "tls": { "expires": 1 } }'

The relay asks this for every session: once when a Client (or a peer relay) connects, again every 30 seconds while it stays connected, and once when it ends. It uses the [auth] url from enrollment.

Switchboard reads the Client’s credential from the query in the request body, usually a Client token as jwt=, and answers with a Grant: what the session may publish and subscribe to, and when it lapses.

Every Grant a Self-hosted relay gets is limited to its Organization’s Namespaces, whatever the Client’s credential says.

Switchboard answers from the location nearest the relay, and keeps answering while the rest of Switchboard is down. If the relay can’t reach it at all, sessions already running continue until their Grant’s expires, which is at most 5 minutes away. New sessions are refused.

jwt
required
string

The relay’s own Node key, not the Client’s token.

Media typeapplication/json

Sent by the relay. Switchboard reads the fields below and ignores the rest.

object
id

The session’s ID.

string
event
required
string
Allowed values: connect revalidate end
transport
string

Example

quic
path

The path the Client dialed.

string

Example

acme/room/42
query

The Client’s raw query string. Its last jwt= is the credential.

string

Example

jwt=eyJhbGciOiJIUzI1NiIs...
tls

Present when the Client presented a certificate the relay verified.

object
expires
integer

Admitted, with this Grant.

Media typeapplication/json

Moq-relay’s Grant. publish and subscribe are patterns relative to the dialed path: ** is everything, live/** is live and everything under it.

object
publish
Array<string>
subscribe
Array<string>
expires

When the session ends if no revalidation succeeds before then. At most 5 minutes out, and never later than the Client token’s own expiry.

integer
revalidate

Seconds until the relay asks again. Currently 30.

integer
tier

The stats tier the relay counts this session’s traffic under. It appears only when the session is another relay (peer is true) and Switchboard is configured with a peer tier. When it’s absent, the relay counts the session in the default tier, with Client traffic.

string
peer

The session is another relay, not a Client.

boolean

Example

{
"publish": [
"alice/**"
],
"subscribe": [
"**"
],
"revalidate": 30,
"tier": "mesh"
}

Answer to an end event.

The request is malformed. The message says how.

Media typeapplication/json
object
error
required
string

Example generated

{
"error": "example"
}

The relay’s own credential is missing or unknown.

Media typeapplication/json
object
error
required
string

Example generated

{
"error": "example"
}

The session is refused. The message says why, and the relay writes it to its log. The Client sees a 401.

Media typeapplication/json
object
error
required
string

Examples

{
"error": "the token has expired"
}