Skip to content

v0.3.4

Choose a tag to compare

@panyam panyam released this 08 Nov 20:11
· 21 commits to main since this release

v0.3.4

A client can now stay in its room past its token's expiry. Until this release
the relay ended a connection at the token's exp, and a CollabClient with
getToken rejoined under a new clientId. Every other peer saw it leave and
join again, once per token lifetime. Now the client hands the relay a fresh
token over the open socket before exp, and nobody sees anything.

Two missions closed with this release, each with an exercise in CI:
make exercise-token-refresh (issue 66) and make exercise-prod (issue 68),
which runs all three mission exercises through the make prod-up stack.

Nothing changes for a client that doesn't set getToken, and a v0.3.3 client
keeps working against this relay (see Compatibility).

Changed (behavior)

  • A CollabClient with getToken refreshes its token in-session (issue
    13, PR 67). Against a v0.3.4 relay it no longer drops and rejoins at each
    exp. It keeps its clientId, and onConnect/onDisconnect don't fire.
    Against an older relay it behaves as before.
  • A failed refresh falls back to a bounded reconnect (PR 67). The client
    retries the refresh at half the time left while 2s or more remain. If none
    succeeds, the relay ends the connection at the old exp and the client
    reconnects through getToken. If the refresh fails again in the next
    lifetime, the session ends with onSessionEnded("token_expired"). That
    stops a client from dropping and rejoining once per lifetime indefinitely.

Added

  • ReAuthAction and ReAuthResult (issue 13, PR 67). A client sends a
    fresh JWT over the open connection. The relay checks it like the upgrade's
    token (signature, issuer, exp, the deny list). The token must have the
    same sub and client_id, and its rooms claim must allow the
    connection's room. On success the connection ends at the new exp. A
    refusal leaves the old exp in place, and ReAuthResult.error says why.
    ReAuth isn't rate limited.
  • RoomJoined.token_expires_at gives the client the first exp. The
    relay sets it only when the connection has a token and the join's
    protocol_version is 3 or higher (PR 71).
  • CollabClientOptions.onTokenRefresh reports each refresh: the new
    expiresAt, or why it failed.
  • Go: RelayAuthenticator.ValidateToken(ctx, raw) and ErrAuthDisabled,
    Guard.Authenticator(), and StreamConfig.Auth. api.go wires the Guard's
    authenticator into every stream, so an embedder with a hand-built Guard
    (as mcpkit has) gets ReAuth without changes.
  • make exercise-prod (issue 69, PR 70) brings up the prod-up stack
    (Caddy with TLS, the relay container, auth from env, the stack's own rate
    limits) and runs the auth, reconnect and token-refresh exercises against
    wss://localhost. A required CI job runs it. The exercises take an
    external relay from MASSRELAY_RELAY_URL.

Fixed

  • A rejoin refused with ROOM_FORBIDDEN stopped silently (PR 67). It
    closed the connection without calling onSessionEnded. It now ends with
    onSessionEnded("token_refused").

Compatibility

  • A v0.3.3 client against this relay keeps working (PR 71). v0.3.3
    rejects JSON fields it doesn't know, so the relay sends
    token_expires_at only to a join with protocol_version 3 or higher.
    CollabClient 0.3.4 sends 3. ts/interop/compat.interop.ts runs the
    published v0.3.3 client against the binary in CI.
  • A v0.3.4 client against an older relay gets no token_expires_at, so
    it never sends a ReAuthAction and reconnects at exp as before. An older
    relay accepts protocol_version 3.
  • CollabClient now ignores event fields it doesn't know, so a later
    relay's additions can't stop it handling an event.

Tests

  • identity.interop.ts flaked about 1 run in 10 on an ordering assertion
    across two senders, which the relay never promised. It now waits for the
    first message before sending the second (PR 67).