Integrate the host application#
This page is for whoever programs the host application: how its server requests the token from Empowerment Center, how the iframe is put on the page and how to talk to it. There are two ways: with the ECenter SDK, which solves almost everything, or by hand with the message protocol.
Before you start#
- The host application has to be registered in Administration › Embedding, with the page's origin, the allowed content, the reader roles and an active credential (see Embedding).
- The host application already knows who its user is: it authenticates them and decides for which ECenter user it requests the token. The login in ECenter has to match the host user's, or the host has to know how to translate it.
- The application's Test tab gives a sample HTML snippet and shows the iframe's messages: use it before programming.
Warning
The token is always requested from the host's server, never from the browser. The embedding credential allows requesting a token for any reader: if it reached the browser, anyone could see everything as another user.
The walkthrough#
- The page loads the iframe
https://ecenter.example.org/embed/<key>. ECenter only lets it be framed from the application's origins. - The iframe notifies the page with the
readymessage. - The page requests a token from its own server.
- The host's server requests the token from ECenter with its credential (
POST /api/embed/v1/tokens) for the user who has signed in. - The page gives the token to the iframe with the
tokenmessage. - The iframe redeems the token for an embedded session and shows the content.
- When the session reaches its maximum, is closed or the iframe is reloaded, it sends
tokenRequiredand it repeats from step 3.
Request the token (host server)#
curl -s -X POST "https://ecenter.example.org/api/embed/v1/tokens" \
-H "Authorization: Bearer $ECENTER_EMBED_SECRET" -H "Content-Type: application/json" \
-d '{
"user": "comercial.norte",
"target": { "workbook": "5b0e…", "document": "c1f7…" },
"ui": { "header": true, "theme": "LIGHT" },
"viewer": "intranet:comercial.norte"
}'
Response 201:
{ "token": "eyJ…", "expiresAt": "2026-10-17T10:05:00Z", "embedUrl": "https://ecenter.example.org/embed/intranet-comercial" }
| Field | What it is |
|---|---|
user |
The login of the ECenter user who will see the content. They have to be able to be a reader. |
target |
What is embedded, within the allowed content: a published document, { "workbook": …, "document": … }, or a template, { "type": "layout", "layout": …, "pages": ["p1", "p2"] } (without pages, all those allowed). |
restrictions |
Optional. What the token takes away (below). |
ui |
Optional. header (the header with the title and the version, true by default), theme (SYSTEM, LIGHT or DARK), page (the start page of a template) and memberEvents (notify the page of the members the user clicks). |
viewer |
Optional. Who the reader is in the host, only for the audit (it is stored summarized). |
The identifiers of the allowed content, with their names and the pages of each template, are given by GET /api/embed/v1/host/app with the same credential: there is no need to copy them by hand.
The token is a JWT signed by ECenter that lives 5 minutes and is redeemed only once. Do not store it: request a new one each time the iframe asks for it.
Restrictions#
"restrictions": {
"segmentations": [ { "connectionId": "8d6f2c4b-…",
"segmentation": { "root": { "type": "group", "logic": "AND", "children": [ … ] } } } ],
"export": false,
"versions": "LATEST",
"bookmark": null
}
| Field | What it does |
|---|---|
segmentations |
One segmentation per connection that is added with AND to that of the document's section. It cannot be applied to a frozen document or to one of another connection: it is rejected with 400 RESTRICTION_NOT_APPLICABLE, never ignored. |
export |
true allows exporting, if the application's policy allows it. |
versions |
LATEST (only the last published version) or ALL (any, if the application allows choosing a version). |
bookmark or state |
The initial view: a bookmark the user can read, or an unsaved state. At most one of the two. |
Restrictions only take away: what the user sees is decided by their identity and their privileges in ECenter.
Errors when requesting the token#
| HTTP | code |
When |
|---|---|---|
| 401 | INVALID_CREDENTIAL |
The credential is not valid: it does not exist, has expired, has been revoked or its holder is disabled. |
| 403 | NOT_ALLOWED |
The credential's holder no longer has System administration. |
| 403 | EMBED_USER_NOT_ALLOWED |
The user cannot be a reader: they do not exist, are disabled, have neither a role of the application nor Portal access, or have System administration. |
| 403 | EMBED_CONTENT_NOT_ALLOWED |
The content is not allowed or the user cannot read it now. |
| 403 | EMBED_BOOKMARK_NOT_ALLOWED, EMBED_VERSION_NOT_ALLOWED, EMBED_EXPORT_NOT_ALLOWED |
The bookmark, the version or the export are not allowed. |
| 403 | EMBED_APP_DISABLED |
The application is disabled. |
| 400 | RESTRICTION_NOT_APPLICABLE |
A segmentation on a frozen document or on one of another connection. |
| 422 | INVALID_SEGMENTATION |
The segmentation is not valid. |
| 403 | LICENSE_INVALID |
No valid license. |
| 404 | EMBEDDING_DISABLED |
Embedding is disabled. |
| 429 | RATE_LIMITED |
The application has exceeded 600 tokens per minute. Wait for what Retry-After says. |
Close a user's sessions#
When the user leaves the host, its server can close all their embedded sessions in the application:
curl -s -X DELETE "https://ecenter.example.org/api/embed/v1/host/sessions?user=comercial.norte" \
-H "Authorization: Bearer $ECENTER_EMBED_SECRET"
With the same credential, GET /api/embed/v1/host/sessions lists the application's open sessions and DELETE /api/embed/v1/host/sessions/{ref} closes one.
Put the iframe with the SDK#
The SDK is a dependency-free JavaScript file that ECenter itself serves: /embed/sdk/v1/ecenter-embed.js. It creates the iframe, gives it the token when it asks for it and requests it again by itself each time it is needed.
<div id="ventas"></div>
<script src="https://ecenter.example.org/embed/sdk/v1/ecenter-embed.js"></script>
<script>
const embed = ECenterEmbed.mount(document.getElementById('ventas'), {
url: 'https://ecenter.example.org/embed/intranet-comercial',
title: 'Sales by zone',
// Requests the token from YOUR server, which requests it from ECenter with the credential
fetchToken: () => fetch('/ecenter/token', { method: 'POST' })
.then((r) => r.json()).then((b) => b.token),
onEvent: (message) => console.log(message.type),
});
</script>
mount option |
What it is |
|---|---|
url |
The iframe's address, https://…/embed/<key>. Mandatory. |
title |
The iframe's title, for accessibility. Mandatory. |
fetchToken |
A function that returns a promise with the token. It is called at the beginning and with each tokenRequired; it receives { reason }. Mandatory. |
onEvent |
Receives each valid message from the iframe and those of the SDK (tokenError). |
autoResize |
true by default: adjusts the iframe's height to that of a template. |
height |
The initial height (480px by default). |
sandbox, allow |
To change the recommended sandbox and allow="fullscreen". |
language |
The language of the content: es, en, ca, eu or gl. It goes in the iframe's address (?lang=). Without it, the installation's. To change it, mount the iframe again. |
The object it returns has setFilters(filters), navigate(page), setTheme('SYSTEM' | 'LIGHT' | 'DARK'), logout(), requestToken() and destroy().
- If
fetchTokendoes not respond within 15 seconds, the SDK considers it failed (tokenErrorwithTOKEN_FETCH_TIMEOUT) and lets another be requested. - To avoid a loop of rejections, it does not request more than 6 tokens in a minute.
- After
logout()it does not open the session again by itself: for another,requestToken(). - The SDK supports
integritywithcrossorigin="anonymous".
Put the iframe by hand#
Without the SDK, the page talks to the iframe through postMessage. All messages carry { v: 1, type, … }. This is the snippet the Test tab gives:
<iframe id="ecenter" title="Sales by zone" src="https://ecenter.example.org/embed/intranet-comercial"
style="width: 100%; height: 600px; border: 0" allow="fullscreen"></iframe>
<script>
const frame = document.getElementById('ecenter');
const origin = new URL(frame.src).origin;
window.addEventListener('message', async (event) => {
if (event.source !== frame.contentWindow || event.origin !== origin || event.data?.v !== 1) return;
if (event.data.type === 'ready' || event.data.type === 'tokenRequired') {
// Your server requests the token with the credential (POST /api/embed/v1/tokens) and gives it to this page
const { token } = await (await fetch('/ecenter/token')).json();
frame.contentWindow.postMessage({ v: 1, type: 'token', token }, origin);
}
if (event.data.type === 'resize') frame.style.height = event.data.height + 'px';
});
</script>
Security rules of the protocol:
- Always send messages to ECenter's exact origin, never to
*. - Accept only messages whose
event.sourceis the iframe and whoseevent.originis ECenter's. - The bearer of the embedded session never leaves the iframe: the page only sees the 5-minute token.
| Direction | Messages |
|---|---|
| Page → iframe | token (with token), setFilters (master filters with filter, or by dimension with dimension, which apply to every document, indicator and text value that has it: presentation, not security), navigate (with page), setTheme (with scheme) and logout |
| Iframe → page | ready, tokenRequired (with reason), loaded (title, type, version and filters), resize (with height), filtersChanged, pageChanged, memberActivated (only with ui.memberEvents), linkOpened, error (with code and message) and sessionEnded (with reason) |
logout closes the session with the reason EMBED_LOGGED_OUT: the iframe sends sessionEnded and does not request another token.
The token can also be given in the address fragment (/embed/<key>#token=…), which does not reach the server or the Referer and which the iframe deletes on reading it. Never in the query string (?token=) or in the path.
What the reader sees#
Inside the iframe, the reader sees the document or the template without the ECenter sidebar: an optional reduced header (title, version and export, if allowed) and, in a template, the tabs of its allowed pages, the master filter bar and its blocks. The viewers are the portal's, without SQL.
While it waits for the token it says “Waiting for the application's authorization…”. If something fails, it shows a message without account data:
| What the reader sees | Cause |
|---|---|
| “Access has expired” | The token passed its 5 minutes without being redeemed. |
| “The access had already been used” | The token had already been redeemed: each authorization works only once. |
| “Access is not valid” | The token does not belong to this application or cannot be verified. |
| “The session has ended” | Inactivity, maximum length or whoever administers closed it. |
| “The session has been closed” | The host sent logout. |
| “The content is not available here” | The page's origin is not among the application's. |
| “You do not have access to this content” | The user cannot be a reader. |
| “The content is not available” | The content is no longer published, the application is disabled, the license is not valid or another reason. |
The sample host#
The repository includes a sample intranet, without dependencies (Node 18 or later), in tools/demo-data/embed-host/server.mjs. It shows how each token is requested from the server for the user who has signed in, how it is renewed by itself with the SDK, how the session is closed in ECenter when leaving the intranet and how to ask what can be embedded.
export ECENTER_URL=https://ecenter.example.org # where the browser loads the SDK and the iframe from
export ECENTER_EMBED_APP=intranet-comercial # the application's key
export ECENTER_EMBED_SECRET=ect_… # the embedding credential (never in the page)
node tools/demo-data/embed-host/server.mjs # listens on http://localhost:4300
EMBED_HOST and EMBED_PORT say where it listens (it has to be one of the application's origins) and EMBED_USERS, which users can “sign in” to the intranet.
Checks before production#
- ECenter and the host go over
https, and the host's origin is among the application's. - The token is requested from the host's server, for the user it has authenticated, and is never stored.
- The credential's secret is in the server's secret store, not in the code or the page.
- No proxy adds
X-Frame-Optionsor anotherContent-Security-Policyto/embed/. - With several instances, affinity by
X-ECenter-Embed-Session. - On leaving the host,
logout()is called and the user's sessions are closed. - There is a planned date to rotate the credential before it expires.