Sessions

How your server opens the editor for one of your users, and how the editor proves where it is loaded.

View as Markdown

A session is the only way into the editor. Your server creates it with a secret key, so your users never hold a key and never see a Muzekit login.

The flow

  • Your serverholds the secret key
  • Muzekit APIapi.muzekit.com
  • Your pagethe SDK and the editor
  1. 1
    Your serverMuzekit API
    POST /v1/sessions
    the user, the mode, a template
  2. 2
    Muzekit APIYour server
    client_secret
    single use, 10 minutes
  3. 3
    Your serverYour page
    hands the secret to the page
  4. 4
    Your pageMuzekit API
    Muzekit.mount exchanges it
    checked against your allowed domains
  5. 5
    Muzekit APIYour page
    editor opens for that user
    token refreshes while it's open
Your users never hold a key or see a Muzekit login.
  1. Your server calls POST /v1/sessions with the user, the mode and, optionally, a template to open.
  2. Muzekit returns a client_secret: single use, valid for 10 minutes.
  3. Your page mounts the editor with that secret. The editor exchanges it for a session token that lasts 15 minutes and refreshes while the editor is open, up to 12 hours.
  4. The exchange checks the page that embeds the editor against your allowed domains. Any other page is refused.
Never send a secret key to a browser

Create sessions on your server. If a key leaks, revoke it in the dashboard: it stops working at once.

Create a session

Shell
curl https://api.muzekit.com/v1/sessions \
  -H "Authorization: Bearer $MUZEKIT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5b0f6a2e-…" \
  -d '{
    "user": { "id": "user_42", "name": "Ada", "email": "[email protected]" },
    "mode": "fill",
    "template": "tpl_vQ8VEOnjY5H"
  }'

Full reference: Create a session.

Users are upserted

user.id is your own id for the person. The first session creates the Muzekit user; later sessions with the same id update their name, email and locale and reuse their templates and assets.