WOPI mode
Open OpenCanvas from an existing WOPI host such as Nextcloud: discovery, the WOPISrc allow-list, CheckFileInfo, GetFile, PutFile and PUT_RELATIVE.
For hosts that already open Collabora / Office Online through WOPI (Nextcloud, ownCloud, Seafile, …). OpenCanvas is the WOPI client; you are the WOPI host. Reference host: examples/wopi-host/server.mjs; end-to-end check: scripts/e2e-wopi.sh.
Register (no JWT key needed):
[[host]]
id = "nextcloud"
name = "Nextcloud"
mode = "wopi" # or "both" (JWT launches + WOPI launches)
wopi_allowlist = ["https://cloud.example.com/index.php/apps/richdocuments/wopi"]
allowed_origins = ["https://cloud.example.com"]
api_key = "env:NC_OC_API_KEY" # optional, for the §7 REST API
[host.flags]
on_conflict = "copy" # copy = PUT_RELATIVE | reload
wopi_allowlist entries are scheme://host[:port][/path]. A WOPISrc is accepted only when scheme, host and port match an entry exactly and the path starts with the entry's path at a / boundary; URLs with userinfo, a query, a fragment, or longer than 255 characters are refused (403 WOPISRC_NOT_ALLOWED) before anything is called. Write localhost and 127.0.0.1 separately if you need both. Redirects are never followed.
Discovery. GET /hosting/discovery returns WOPI discovery XML (net-zone external-http(s) from OC_PUBLIC_URL): app application/vnd.opencanvas+zip with edit (default) and view for ext="ocanvas", app text/markdown with edit, view and convert (targetext="ocanvas") for ext="md", and Capabilities → GET /hosting/capabilities. Every urlsrc is {OC_PUBLIC_URL}/v1/launch?; append WOPISrc=<urlencoded> (and any other placeholders, which are ignored), Collabora style.
Launch. Your page form-POSTs access_token and access_token_ttl (ms since the epoch; 0 or absent = 10 h) into an iframe at /v1/launch?WOPISrc=<urlencoded https://host/wopi/files/<id>>. We answer 303 /app/#t=<ticket>, like a JWT launch. The session expires at access_token_ttl, capped at 10 h from the launch like a JWT session (SEC-35); after that, launch again (the editor's Action_RefreshToken renewal is a fresh launch). 401 TOKEN_INVALID when CheckFileInfo answers 4xx or the ttl has passed. The access token is opaque to us, sealed at rest under OC_KEK like a callback token, sent only in the query string of calls to WOPISrc (as WOPI requires), and never logged. The file id (room, REST API path) is the normalized WOPISrc: URL-encode it in /v1/files/{fileId}/….
We call:
GET {WOPISrc}?access_token=…→ CheckFileInfo (at launch, on load, and before a save when the file name is not known). We readBaseFileName,Size,Version,LastModifiedTime,UserId,UserFriendlyName,UserExtraInfo.avatar(http(s) only),UserExtraInfo.detail(the person's second line, docs/21),UserCanWrite,ReadOnly,UserCanNotWriteRelative,DisableExport,DisablePrint,HideExportOption,FileVersionUrlandFileVersionPostMessage(a link to your own version page; http(s) only), and our extensionsOpenCanvas_UserCanComment,OpenCanvas_SupportsVersions(you implement the two version calls below),OpenCanvas_UserCanSeeHistory(viewers may see history) andOpenCanvas_DisableRestore. Role:UserCanWriteand notReadOnly→edit; elseOpenCanvas_UserCanComment→comment; elseview. Perms:DisableExport→ no export, download or print;HideExportOption→ no export;DisablePrint→ no print (PDF). The tracked version isLastModifiedTime(Versionis shown only when there is noLastModifiedTime, and then no timestamp is sent).GET {WOPISrc}/contents?access_token=…→ GetFile (≤ 100 MB). Empty body = new canvas..ocanvaszip, or Markdown whenBaseFileNameends in.md.POST {WOPISrc}/contents?access_token=…→ PutFile, body.ocanvas(or Markdown for.mdfiles — lossy for boards and databases), headersX-WOPI-Override: PUT,X-COOL-WOPI-Timestamp: <LastModifiedTime we loaded / last saved>,X-COOL-WOPI-IsAutosave: true(falsefor a named or restore save, withX-OpenCanvas-Commit-Message,X-OpenCanvas-Restored-From),X-COOL-WOPI-IsModifiedByUser: true, andX-OpenCanvas-Checkpoint: 1as in §5. Answer200 {"LastModifiedTime":"…"}(without it we ask CheckFileInfo).409 {"COOLStatusCode":1010}= the file changed elsewhere → youron_conflictpolicy runs (any other 409 is retried like an outage). Saves go through the same outbox, retries and autosave rules as JWT mode (docs/15 §7).POST {WOPISrc}?access_token=…withX-WOPI-Override: PUT_RELATIVE,X-WOPI-SuggestedTarget: <UTF-7 "<name> (conflict copy).ocanvas">,X-WOPI-Size→ conflict copy (policycopy). Answer{"Name","Url","HostEditUrl"|"HostViewUrl"}; editors are told theHostEditUrlandUrlwithout its token. Hosts that setUserCanNotWriteRelativeshould useon_conflict = "reload".
No LOCK/UNLOCK (we use timestamps, like Collabora).
Proof keys (§6.4, WOPI-13). Every call OpenCanvas makes to your WOPI host (CheckFileInfo, GetFile, PutFile, PUT_RELATIVE, and any later override) carries the Microsoft proof headers:
X-WOPI-TimeStamp: .NET ticks (100 ns since 0001-01-01 UTC) of the call.X-WOPI-Proof: base64 RSASSA-PKCS1-v1_5 / SHA-256 signature with the current key.X-WOPI-ProofOld: the same bytes signed with the old key.
The signed bytes are be32(len token) ‖ access_token (UTF-8) ‖ be32(len URL) ‖ UPPERCASE(full request URL, query and access_token included) ‖ be32(8) ‖ be64(timestamp). Discovery publishes both public keys in the spec format, a CryptoAPI PUBLICKEYBLOB (base64) plus modulus and exponent (base64, big-endian):
<proof-key oldvalue="BgIAAACkAABSU0Ex…" oldmodulus="…" oldexponent="AQAB"
value="BgIAAACkAABSU0Ex…" modulus="…" exponent="AQAB"/>
A host accepts the call when X-WOPI-Proof verifies with the current key, or X-WOPI-ProofOld with the current key, or X-WOPI-Proof with the old key; refuses a timestamp older than 20 minutes; and answers 500 otherwise (after re-reading discovery once, in case the keys rotated). examples/wopi-host/server.mjs does exactly this (checkProof); WOPI_PROOF=off opts it out for servers without keys. Nextcloud, ownCloud and Seafile verify these headers the same way they do for Collabora.
Key configuration and rotation. OC_WOPI_PROOF_KEY is the path of a 2048-bit (or larger) RSA private key, PEM (PKCS#8 or PKCS#1), or the same PEM sealed with OC_KEK (opencanvas seal-proof-key < key.pem > key.sealed). OC_WOPI_PROOF_KEY_OLD is the previous key in the same forms; without it the current key is published and used as the old one. With OC_DEV=1 and no key, a pair is generated at start-up (it changes on every restart). Start-up refuses a hosts file with a WOPI host when there is no key. Rotation: generate a new key (openssl genrsa -out new.pem 2048), set OC_WOPI_PROOF_KEY_OLD to the current key and OC_WOPI_PROOF_KEY to the new one, roll every node (they must share the keys); hosts accept both while their cached discovery catches up. Drop the old key at the next rotation.
Assets. WOPI has no asset API, so uploads (POST /v1/assets?ticket=) are kept with the room and answered 201 {"assetId":"a_…","url":"/v1/assets/a_…","mime","size"}. They are served by GET /v1/assets/:id?ticket= (images inline, anything else as a download, nosniff, sandboxed) and inlined into the saved .ocanvas as assets/<id> (stored) plus assets/index.json ({"<id>":{"mime","size"}}); only assets the document still references are written. On load they are read back out of your file. Limits: 10 MB per asset, 50 MB of assets per file (413 ASSET_TOO_LARGE); the whole zip stays under the 100 MB .ocanvas read limit. DOCX, PDF and .ocanvas exports include them too.
Mentions. The member list is the users who have opened the file (from CheckFileInfo, with their detail) and the saved people map: the no-source case of §5 "People". Mention notifications (POST /mentions, §5) are not sent in WOPI mode.
Generated from docs/05-INTEGRATION-GUIDE.md in the repository; edit it there. Last changed .