You're reading the docs for dotwire 0.4. The latest release is 0.5. Upgrading? See Upgrading to 0.5.
Auth
dotwire issues nothing and stores no credentials. Your host application holds an RS256 private key and mints JWTs. dotwire holds only the matching public keys and verifies signatures, so it can never mint a token itself.
The token's sub is your user id. dotwire treats it as an opaque string and uses it to look up roles and room memberships in its own tables. It must be stable and unique per user. User ids are 1 to 256 characters with no control characters.
Token contract
Contract (AUTH.md, "Token contract (normative)")
Every JWT presented to dotwire must satisfy the following. This table is the contract host integrators build against; nothing beyond it is required, and nothing on it is optional except where marked.
| Claim | Required | Meaning |
|---|---|---|
iss | yes | Host identifier; must match dotwire's configured issuer. |
sub | yes | The host's user id — an opaque string, never interpreted by dotwire beyond identity/lookup. 1–256 characters, no control characters (U+0000–U+001F, U+007F); a token whose sub breaks this is rejected. |
aud | yes | Must match dotwire's configured audience. |
exp / iat | yes | Standard expiry/issued-at claims, both enforced: a token without iat, with iat in the future, or with exp - iat above Auth:MaxTokenLifetimeMinutes (default 60, 0 disables the cap) is rejected. Clock skew tolerance is Auth:ClockSkewSeconds (default 30). Short TTLs are recommended (guidance: 5–60 minutes) — see "Threat notes" for why. |
dw:role | yes | Namespaced custom claim; one of member | auditor | admin. Cross-checked against the service-side user_roles table (see "Authorization pipeline") — the JWT's claim is treated as a hint, not a grant. |
dw:name | no | Optional display name. |
Contract (AUTH.md, "Token contract (normative)")
Header:
kid(key id) is required in every token's header — it is how dotwire selects which public key to verify against, whether the key came from a JWKS endpoint or inline config.Signing: RS256 only. dotwire's JwtBearer configuration does not accept HS256 or any symmetric algorithm — see "Threat notes" for why that restriction is load-bearing rather than incidental. Keys must be at least 2048-bit RSA; inline keys must be public-key PEM (a private key in
Auth:Keysfails startup), and JWKS keys below 2048 bits are ignored.Transport: send the token in the
Authorization: Bearerheader. The only exception is the browser WebSocket upgrade, which cannot carry headers:?access_token=is accepted only onGET /hub/roomsandGET /rooms/{uuid}/events, and only when noAuthorizationheader is present. Tokens in URLs end up in proxy logs, so keep their TTL short and run every hop over TLS.
A token with no sub, or with a dw:role other than the three role names, is rejected at authentication.
Minting tokens
Both host SDKs mint tokens that satisfy the contract.
Node.js (@dotwire/host)
const token = await host.mintToken('alice', {
role: 'member',
displayName: 'Alice Smith',
ttl: '1h'
});
.NET (Dotwire.Host)
string token = client.MintToken("user-42", role: "member");
You can also mint tokens with any JWT library, as long as the result follows the contract above. AUTH.md in the dotwire repository has host-side examples for System.IdentityModel.Tokens.Jwt and jsonwebtoken.
Verification keys
Configure at least one key source. dotwire refuses to start without one, and without Auth:Issuer and Auth:Audience.
- Inline PEM keys. Set
Auth:Keys:<kid>to a PEM-encoded RSA public key of at least 2048 bits, for exampleAuth__Keys__devas an environment variable. Use this for simple or airgapped deployments. - JWKS URL. Set
Auth:JwksUrlto a standard JSON Web Key Set endpoint. It must behttpsor a loopback host unless you setAuth:AllowInsecureJwksUrl=true. dotwire fetches it once at startup and refreshes it in the background everyAuth:JwksRefreshMinutes(5 by default), and also, rate-limited, after it sees an unknownkid. A token with an unknownkidis rejected at once rather than waiting for a fetch. If a refresh fails, or returns no usable key, dotwire keeps the previous keys. Responses are capped at 256 KiB. An inline key wins over a JWKS key with the samekid.
Rotating keys
- JWKS: publish the new key under a new
kid, and keep the old key published until every token signed with it has expired. Allow for the refresh interval as well as the token TTL. - Inline: add the new key under a new
kid, keep the old entry until its tokens expire, and restart dotwire. There is no live polling.
Roles
There are three roles, stored in dotwire's user_roles table. They are independent, not a hierarchy.
memberis the role for ordinary participants. It grants no rooms by itself. Room access comes from room membership.auditorgrants read access to the audit log and nothing else.adminmanages the service: roles, room membership, message injection, redaction, retention, and DSAR export. It grants no room access and no audit access.
An admin who needs to read a room must also be a room member. An admin who needs the audit log needs the auditor role, which means a separate user id, because each user has one role.
An admin can't change or delete their own role (409 self_role_change), and nobody can demote or delete the last remaining admin (409 last_admin). Beyond that, any admin can grant admin or auditor to any user. There is no second approver, so every grant is audited (role.set.*) and separation of duties comes from reviewing the audit trail.
The migrations seed two identities so a host can use the admin and audit APIs right away: host-admin with admin, and host-auditor with auditor. Both host SDKs sign admin and audit calls as these users by default.
Authorization pipeline
Contract (AUTH.md, "Authorization pipeline")
Every authenticated request or connection goes through this pipeline, in this exact order. The order matters: each stage is only meaningful once the stage before it has passed.
- Signature verification. The token's
kidselects a public key (from JWKS cache or inline config); the signature is verified against it. Fails closed — an unrecognizedkidor bad signature is rejected before anything else is inspected.- Standard claims.
exp,aud, andissare checked. An expired token, wrong audience, or wrong issuer is rejected here, before any dotwire-specific claim is consulted.- Role cross-check. The token's
dw:roleclaim is compared against the service-sideuser_rolestable for thatsub. The table is authoritative, not the claim — if they disagree, the request is denied. This is what makes a stolen or stale token claimingadminharmless if the table says otherwise: revoking or demoting a user inuser_rolestakes effect immediately, without waiting for outstanding tokens to expire.- Room membership check. For room-scoped operations, membership is checked against the
room_memberstable (host-managed via the admin API). This check happens at CONNECT, not per message — the result is cached on the connection and invalidated only by membership-change events, per ARCHITECTURE.md's "Concurrency and fanout disciplines." A per-message membership query would put the database on the fanout hot path; this contract is what keeps it off. Hub sends (Dotwire:HubSend:Enabled) rely on that same connection-cached subscription.
In practice:
- A failed signature or standard-claim check returns
401. - A user with no row in
user_roles, or a row that doesn't match the token'sdw:role, gets403. /adminroutes requireadminin both the token and the table./auditroutes requireauditorin both.- REST room routes check membership on every request. The hub checks it when a connection calls
Subscribe, and gateways re-check every live subscription everyDotwire:MembershipSweepSeconds(60 by default). See Rooms and membership.
Token lifetime
dotwire has no revocation list for individual tokens. The role cross-check handles demotions immediately, but a still-valid token remains a credential until it expires, so keep TTLs short and refresh them.
When a token expires, dotwire closes the hub connection and ends any SSE stream that used it. When you configure tokenUrl, @dotwire/client fetches a fresh token from your token endpoint 30 seconds before the cached one expires, by default.
Two key systems
JWT signing keys authenticate people. dotwire's encryption keys protect data at rest. They are unrelated, and losing each has a different consequence. See Encryption and retention.
Related
- Rooms and membership: stage 4 of the pipeline.
- Integrate a host app: building a token endpoint.
- Configuration reference