Mints a user token for one signed-in user of your app. Call it from your backend, never from the app: it needs a secret key.
A user token reaches one project and one app user, and lasts at most one hour. It carries scopes: the ones scopes names, or without it every one of colocation and vps that the minting key holds, and a key may mint only scopes it holds. User tokens are accepted by the co-location room operations, the co-location relay and the Advanced VPS operations; every other operation refuses them. Treat the token as opaque.
Deleting or expiring the secret key that minted a token revokes the token too. There is no other way to revoke one.
Mint only for a user your backend has signed in. If you need more protection against automated clients, your endpoint can first check App Attest (iOS), Play Integrity (Android) or Meta's attestation (Quest).
Limits, always enforced: 1,200 tokens a minute per key, and 60 an hour per key and app user. A backend can cache a token per app user until shortly before expires_at.
Your backend
Mint a token for the signed-in user and return it to the app:
const r = await fetch("https://platform.reactvision.xyz/functions/v1/app-user-tokens", {
method: "POST",
headers: { "x-api-key": process.env.RV_SECRET_KEY!, "content-type": "application/json" },
body: JSON.stringify({ project_id: PROJECT_ID, app_user_id: user.id }),
})
const minted = await r.json() // { token, expires_at, expires_in, scopes }: return it to the signed-in app user as it is
Your app (Viro)
Viro calls credentials before every VPS request, a frame a second in server mode, and when a device joins a co-location room, so let createUserTokenCredentials keep the token. It asks your backend again only when the token is close to expiring or was refused, and Viro then sends the refused request once more with the new token.