Authentication

Two kinds of credentials, one check. Your server uses the host key; code that acts for one of your users carries a short-lived token that your application mints. OpenCanvas never issues user tokens and runs no OAuth server.

Host key

Server to server, send your host id and the host's api_key (from the hosts file) on every request. The host key has full access to your host's files, the admin operations included.

HeaderValue
X-OpenCanvas-HostYour host id, for example acme.
X-OpenCanvas-KeyThe host's api_key. Keep it on your server; never send it to a browser.
X-OpenCanvas-AuthorOptional. The user id a change is attributed to: its edit origin becomes api:<userId>. Default svc:<hostId>.
X-OpenCanvas-Callback-TokenOptional. A bearer OpenCanvas passes on the callbacks this call causes (loading the file when nobody has it open, saving it).
Host key
curl -s "https://canvas.example.com/api/v1/files/doc_1?format=outline" \
  -H "X-OpenCanvas-Host: acme" \
  -H "X-OpenCanvas-Key: $OC_API_KEY" \
  -H "X-OpenCanvas-Author: u_42"

User tokens

For code that acts for one of your users (an integration running as that user, a script a user starts), mint a JWT for that user and send it as Authorization: Bearer <token>. You sign it with the same keys as launch tokens: the host's jwt_secret (HS256), or your private key when the host has jwt_public_key (RS256, EdDSA) or jwt_jwks_url.

ClaimValue
issYour host id, or [host.api] issuer. It picks the host, so it must be unique among the server's hosts.
aud{[host.api] audience or OC_PUBLIC_URL}/api/v1, for example https://canvas.example.com/api/v1. A launch token or an MCP token (audience .../mcp/{hostId}) is refused here.
subThe user id, as in launch tokens. svc:<name> for a backend job.
expAt most 15 minutes ahead of the server's clock (with 30 seconds of leeway). nbf is honoured.
scopeSpace-separated: canvas:read, canvas:comment, canvas:write, canvas:admin.
roleThe user's role on the files: view, comment or edit (absent: view). Used only when you do not implement POST /access.
filesThe file ids the token covers. Required when you do not implement POST /access, unless the host sets [host.api] all_files = true.
nameOptional display name, shown with the user's changes.

The audience is never taken from the request: without OC_PUBLIC_URL or [host.api] audience, user tokens are off for the host and answer 401 TOKEN_INVALID.

[host.api]
issuer      = "acme"                        # default: the host id
audience    = "https://canvas.example.com"  # default: OC_PUBLIC_URL
all_files   = false                         # true: without /access, a token with no `files` covers every file
token_admin = false                         # true: tokens with canvas:admin may use the admin operations
Mint a user token and call the API
# HS256 with the host's jwt_secret, using only openssl.
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
now=$(date +%s)
header=$(printf '{"alg":"HS256","typ":"JWT"}' | b64url)
claims=$(printf '{"iss":"acme","aud":"https://canvas.example.com/api/v1","sub":"u_42","scope":"canvas:read canvas:comment","role":"edit","files":["doc_1"],"iat":%d,"exp":%d}' \
  "$now" "$((now + 600))" | b64url)
sig=$(printf '%s.%s' "$header" "$claims" | openssl dgst -sha256 -hmac "$ACME_OC_SECRET" -binary | b64url)
TOKEN="$header.$claims.$sig"

curl -s "https://canvas.example.com/api/v1/files/doc_1/comments" \
  -H "Authorization: Bearer $TOKEN"

Scopes

A token's scope is a ceiling: the operation's x-opencanvas-scope in the OpenAPI document must be within it, or the answer is 403 SCOPE_REQUIRED. Each scope includes the ones above it.

ScopeAllowsLeast roleOperations
canvas:readRead canvases, blocks, databases, boards, comments and members; export; stream events; a sync ticket with the view role.viewreadFile, listBlocks, getBlock, findBlocks, listDatabases, getDatabase, queryRows, readBoard, listComments, listMembers, exportFile, renderFile, listReferences, streamEvents, createSyncToken, convert, extract, search, listAutomations, listAutomationRuns, listBacklinks, getGraph
canvas:commentEverything canvas:read allows, and start or reply to comment threads.commentaddComment
canvas:writeEverything canvas:comment allows, and change blocks, databases and boards, and import. canvas:write:direct counts as canvas:write.editbatchBlocks, createDatabase, upsertRows, addField, createBoard, addShapes, makeLive, importFile, testAutomation, saveAutomation, deleteAutomation, enableAutomation
canvas:adminSave now, change a user's role, close the session, drop cached members. Counts for tokens only when the host sets [host.api] token_admin = true; otherwise these are the host key's.host key, or a token with canvas:admincommitFile, setRole, closeSession, invalidateMembers, offlineRevoke

Roles

The effective permission is min(scope, role). A canvas:write token does not let a view user write, and a canvas:read token does not let an editor write.

  • Where the role comes from. If you implement the optional POST /access callback, OpenCanvas asks it for the user's role on each file a call touches (cached 30 seconds, dropped by the role API) and ignores the token's role claim; none refuses every operation. Without it, the role claim counts, but only for the files listed in files (403 FILES_REQUIRED otherwise, unless [host.api] all_files = true).
  • Revocation. After POST /api/v1/files/{fileId}/role with "role": "none", the user's next call is refused, and their event streams close with code 4003.
  • The host key acts with the edit role on every file, plus the admin operations.

Expiry

Tokens live at most 15 minutes: an exp further ahead than that is refused (401 TOKEN_INVALID). An expired token answers 401 TOKEN_EXPIRED; an event stream opened with a token closes with code 4001 when it expires. Mint a fresh token per job or per request: the clients take a token callback that runs before every request.

Errors

StatusCodeWhen
401UNAUTHENTICATEDNo credentials, an unknown host, or a wrong host key.
401TOKEN_INVALIDSignature, issuer, audience, a lifetime over 15 minutes, not yet valid, or no public base URL for the host.
401TOKEN_EXPIREDThe token's exp has passed.
403SCOPE_REQUIREDThe operation needs a scope the token lacks (admin operations: canvas:admin and token_admin).
403ROLE_FORBIDDENThe user's role on the file is too low, the file is not in files, or access was revoked.
403FILES_REQUIREDNo POST /access callback, and the token lists no files.

401 answers carry WWW-Authenticate: Bearer realm="opencanvas" (with error="invalid_token" for token problems). The MCP endpoint uses the same check with its own audience; see AI and MCP.

Last changed .