iFrame Guide
Read this if you want to add OfficeX as a UX lego within your app
Anonymous OfficeX is designed for whitelabel with zero dependencies. Any developer can add anon workspaces to their app in just 2 mins.
The below iframe examples showcase how easy it is to get started. There are two modes:
ephemeral offlinemode for purely clientside UX without cloudcloud injectedmode for controlled authentication with cloud
Both modes can use iframe.postMessage() commands to control the child iframe from purely clientside. Scroll down to see those commands.
Ephemeral offline mode is a pure clientside iframe with no cloud or backend. Its primary value is for organizational UX. It is ideal for single-use tools such as YouTube Downloaders and PDF generators.
The below code snippet is a barebones implementation in raw HTML. It has zero dependencies so you can just copy paste it directly.
<iframe
id="officex-iframe"
src="https://officex.app"
sandbox="allow-same-origin allow-scripts allow-downloads allow-popups"
></iframe>
<script>
const iframeElement = document.getElementById("officex-iframe");
iframeElement.onload = () => {
iframeElement.contentWindow.postMessage(
{ type: "officex-init", data: { ephemeral: {} }, tracer: "my-tracer" },
"https://officex.app"
);
};
</script>Additionally, you can provide extra arguments to the ephemeral mode like so:
profile_entropyis like a password seed phrase to deterministically generate an officex user (which is really just a crypto wallet). The samesecret_entropystring will create the exact same wallet every time.org_entropyis the same, except for deterministically generating an officex organization. While it is possible to useorg_entropyin ephemeral iframes, it is currently not possible in cloud.
The most common reason to use entropy strings is to avoid messy workspaces. Using unique new entropy will create a fresh new organization entirely.
Cloud injected mode inserts auth credentials into iframes so that you can log in your users to give personalized UX within your app. It is ideal for both light & deep integrations, whether you are a chrome extension, mobile app, community platform or professional work tool.
The below code snippet is a sample implementation in raw HTML. The authJson object can be found in your organization settings page. It is also returned back to you in the /quickstart
If you do not want to pass in sensitive api keys to the frontend, you can also use a workaround via shortlinks bypass.
Once you've initialized the cloud injected mode, you can control the UX via iframe.postMessage() or REST API directly.
To see a ReactJS implementation of cloud injected iframe, click the button below to run in codepen.
You can get the authJson for you account from your organization settings page as seen in the GIF below. It is also returned back to you in the /quickstart

Note: It is possible for injected cloud authJson.api_key_value to be an empty string. In this case the officex iframe webapp will attempt to fallback to user private keys if they exist in the browser cache.
Once you've initialized your iframes, you have two ways to control them:
REST API (cloud only)
iframe.postMessage()(works for all)
The REST API method is straightforward, as the frontend will automatically reflect the backend server state. Meanwhile the iframe.postMessage() commands are a custom protocol that works purely clientside. See the commands below.
iFrame PostMessage Commands
iframe.postMessage() commands are a custom protocol that works purely clientside. The commands follow a pattern like so:
The command gets sent to the child iframe OfficeX. It will process it and return back a message to parent webpage. You must listen to the message event from browser. Learn more about iframe.postMessage() here in mdn browser docs.
For a full end-to-end demo of iframe messaging, view the below interactive demo and its github repo.
The list of iframe commands are below.
IFrameCommandType.INIT
Mandatory command in order to initiate the iframe. Include the auth credentials to switch to the right organization and profile.
ephemeral offline
injected cloud
IFrameCommandType.ABOUT
Get info about the current organization and profile in the iframe. Useful for status checks, especially when dealing with multi-tenant environments.
IFrameCommandType.AUTH_TOKEN
Get auth token of the current organization and profile in the iframe. Useful for doing clientside REST API calls, helping simplify in multi-tenant environments without involving backend.
IFrameCommandType.NAVIGATE
Navigate the child iframe to a url. Useful for controlling the child iframe UX from your parent webpage, as if it were part of your app.
Use this in combo with shortlinks if you want to avoid exposing auth credentials to clients.
IFrameCommandType.DIRECTORY_ACTION | CREATE_FILE
Create a file and save it to your child iframe. Files can be uploaded either as a raw_url string or as a base64 file of max 50mb size. For large file uploads, use the OfficeX UMD <script> (coming soon).
raw_url
base64
You can see all the official iframe types for typescript on npm github officexapp/types
Easy Multi-iFrame Management
If your users are often hopping between multiple organizations, we recommend using deterministic iframe profiles with cloud organizations, as that lets you avoid a lot of headache managing api keys per user per org. The ephemeral offline profiles can use their crypto identities to generate temp auth signatures as a form of universal auth for all organizations.
Otherwise you'll need to inject api key per user per organization, and send those to credentials to frontend per user session. We highly recommend you read about common iframe auth flows to understand the tradeoffs.
Feature Flags
App developers can control the OfficeX experience shown to users. While production https://officex.app has sensible defaults, you can customize many options as follows:
This feature is coming soon
iFrames are the primary way to implement OfficeX as a UX lego inside your app. But for some use cases, you might want to just get access to a users pre-existing organization. For those cases, continue to Grant Existing guide next below.
Last updated