# WOPI Integration How Drive talks to Collabora Online, how Collabora talks back, and the iframe dance that ties them together. --- ## What WOPI Is WOPI (Web Application Open Platform Interface) is Microsoft's protocol for embedding document editors in web apps. Collabora implements it. Your app (the "WOPI host") exposes a few HTTP endpoints, and Collabora calls them to read files, write files, and manage locks. The mental model that matters: during editing, the browser talks to Collabora, and Collabora talks to your server. The browser is not in the loop for file I/O. ## The Full Flow Here's what happens when a user double-clicks a `.docx`: ### 1. Token Generation The browser calls our API to get a WOPI access token: ``` POST /api/wopi/token Content-Type: application/json { "file_id": "550e8400-e29b-41d4-a716-446655440000" } ``` The server: - Validates the Kratos session (normal session auth) - Looks up the file in PostgreSQL - Determines write access (currently: owner = can write) - Generates a JWT signed with HMAC-SHA256 - Fetches the Collabora discovery XML to find the editor URL for this mimetype - Returns the token, TTL, and editor URL Response: ```json { "access_token": "eyJhbGciOiJIUzI1NiIs...", "access_token_ttl": 1711382400000, "editor_url": "https://collabora.example.com/browser/abc123/cool.html?WOPISrc=..." } ``` ### 2. Form POST to Collabora The browser doesn't `fetch()` the editor URL — it submits a hidden HTML form targeting an iframe. Yes, a form POST in 2026. This is how WOPI works: the token goes as a form field, not a header. From `CollaboraEditor.tsx`: ```tsx