Skip to content

Commit 4e85fbd

Browse files
update iframe auth docs (#167)
* update iframe auth docs * cellOnClick change
1 parent 1569586 commit 4e85fbd

4 files changed

Lines changed: 106 additions & 0 deletions

File tree

content/workspace/developers/json-specs/widgets-json-reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ A `Widgets.json` table is a configuration structure with any of the named attrib
320320
_Example:_ `"id"`
321321
_Example use case:_ If your table displays company names in the cell but your API expects company IDs, set `valueField: "companyId"` to use the ID field from the row data instead of the displayed name.
322322

323+
- **forceUpdate**
324+
_Type:_ `boolean` (optional)
325+
By default, clicking a cell updates the shared parameter for the other widgets in the group, but the widget containing the clicked cell does not re-fetch its own data. Set this to `true` to force the source widget to update as well when one of its cells is clicked.
326+
_Example:_ `true`
327+
323328
- **colorValueKey**
324329
_Type:_ `string`
325330
Specifies which field to use for determining the color when showing cell changes.

content/workspace/developers/widget-configuration/render-functions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,32 @@ In this example:
235235
]
236236
```
237237

238+
### Using forceUpdate to Refresh the Source Widget
239+
240+
By default, when a cell click updates a parameter through the `groupBy` action, only the other widgets that share the parameter are refreshed — the widget containing the clicked cell does not re-fetch its own data. If the source widget also uses the parameter (for example, the table filters or highlights rows based on the selected symbol), set `forceUpdate: true` so it updates too:
241+
242+
```json
243+
{
244+
...
245+
"columnsDefs": [
246+
{
247+
"field": "symbol",
248+
"headerName": "Symbol",
249+
"renderFn": "cellOnClick",
250+
"renderFnParams": {
251+
"actionType": "groupBy",
252+
"groupBy": {
253+
"paramName": "symbol",
254+
"forceUpdate": true
255+
}
256+
}
257+
}
258+
]
259+
}
260+
```
261+
262+
With `forceUpdate: true`, clicking a symbol cell updates the `symbol` parameter and re-fetches the table widget's own data in addition to updating the other widgets in the group.
263+
238264
### Hover Card
239265

240266
To use the hover card render function, you need to add it to the `columnsDefs` array in your `widgets.json` file for the column you want to apply it to.

content/workspace/developers/widget-parameters/cell-click-grouping.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,31 @@ In this example:
229229
- When displaying human-readable text but needing to pass IDs or codes
230230
- When the displayed value differs from the parameter value format
231231
- When you want to decouple the display value from the API parameter value
232+
233+
## Using forceUpdate to Refresh the Source Widget
234+
235+
By default, clicking a cell only updates the other widgets that share the parameter — the table widget containing the clicked cell does not re-fetch its own data. This avoids unnecessary requests, since the table usually just provides the selection.
236+
237+
If the table widget itself also depends on the parameter (for example, it filters or highlights its rows based on the selected symbol), set `forceUpdate: True` in the `groupBy` configuration so the source widget re-fetches its data as well:
238+
239+
```python
240+
{
241+
"field": "symbol",
242+
"headerName": "Symbol",
243+
"cellDataType": "text",
244+
"width": 120,
245+
"renderFn": "cellOnClick",
246+
"renderFnParams": {
247+
"actionType": "groupBy",
248+
"groupBy": {
249+
"paramName": "symbol",
250+
"forceUpdate": True # Also re-fetch this widget's data on click
251+
}
252+
}
253+
}
254+
```
255+
256+
**When to use forceUpdate:**
257+
258+
- When the table widget's own endpoint uses the parameter being updated
259+
- When clicking a cell should refresh the data shown in the source table, not just the connected widgets

content/workspace/developers/widget-types/iframe.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ keywords:
88
- streamlit
99
- embed external app
1010
- postMessage
11+
- openbb-auth
12+
- auth headers
1113
- mcpUrl
1214
- destructiveHint
1315
- sub-widgets
@@ -24,6 +26,7 @@ On its own, an iframe just renders the URL. But by implementing the **Iframe Wid
2426

2527
- **Export sub-widgets** — declare tables and markdown sections inside the iframe that Workspace can pull out as standalone dashboard widgets.
2628
- **Receive toolbar parameters** — react to Workspace parameters (dropdowns, dates, toggles) without a backend round-trip.
29+
- **Receive auth headers** — get the auth headers configured on the widget's backend connection, so the app can make authenticated API calls without re-prompting for credentials.
2730
- **Auto-connect an MCP server** — wire up Copilot tools the moment the widget mounts.
2831
- **Auto-refresh on mutating tool calls** — remount the iframe after a destructive MCP tool runs so the UI reflects new state.
2932

@@ -92,6 +95,7 @@ The protocol is a small set of `postMessage` events exchanged between the embedd
9295

9396
- **`openbb-request`** — Workspace asks the iframe for a sub-widget's data. A `widgetId` of `null` means "send everything."
9497
- **`openbb-params-update`** — Workspace pushes new toolbar parameter values to the iframe (e.g. the user changed a dropdown). The app reads these and re-renders.
98+
- **`openbb-auth`** — Workspace sends the widget's configured auth headers to the iframe in response to `openbb-connect`. See [Receiving auth headers](#receiving-auth-headers-openbb-auth).
9599

96100
### Sub-widget manifests
97101

@@ -188,6 +192,49 @@ The bridge below is the complete client side of the protocol — announce on loa
188192
})();
189193
```
190194

195+
## Receiving auth headers (`openbb-auth`)
196+
197+
If the widget's backend connection was configured with auth headers (for example an `Authorization` or `X-API-KEY` header entered when the backend was added to Workspace), Workspace forwards those headers to the embedded app so it can make authenticated requests of its own — for instance, calling the same backend the widget belongs to.
198+
199+
The flow is part of the handshake:
200+
201+
1. The embedded app sends `openbb-connect` (as in the [Minimal bridge](#minimal-bridge) above).
202+
2. Workspace replies with an `openbb-auth` message containing the configured headers:
203+
204+
```js
205+
{
206+
type: "openbb-auth",
207+
headers: { "Authorization": "Bearer ...", "X-API-KEY": "..." }
208+
}
209+
```
210+
211+
3. The app stores the headers and attaches them to its API calls:
212+
213+
```js
214+
let authHeaders = {};
215+
216+
window.addEventListener("message", function (event) {
217+
if (event.data?.type === "openbb-auth") {
218+
authHeaders = event.data.headers;
219+
// e.g. re-fetch data now that credentials are available
220+
}
221+
});
222+
223+
// Later, in your data fetching:
224+
fetch("https://my-backend.example.com/portfolio", { headers: authHeaders });
225+
```
226+
227+
Because `openbb-auth` is only sent in reply to `openbb-connect`, register your `message` listener before (or at the same time as) sending the handshake, or the reply may arrive before you are listening.
228+
229+
### Security constraints
230+
231+
Workspace only sends `openbb-auth` when **both** of these hold:
232+
233+
- The backend connection actually has headers configured — if there are none, no message is sent.
234+
- The `openbb-connect` message's origin **exactly matches** the origin of the iframe's `src` URL. The reply is posted targeted at that origin (never `"*"`), so credentials cannot leak to a different origin.
235+
236+
The origin check means pages that send the handshake from a nested sub-frame on a *different* origin than the widget's `endpoint` URL (some component-based frameworks do this) will not receive the headers — send `openbb-connect` from the top-level page of your app in that case.
237+
191238
## Pushing parameters back to Workspace
192239
193240
The protocol messages above cover the **inbound** direction — Workspace pushing parameter values *into* the iframe with `openbb-params-update`. The parameter bridge is the **outbound** direction: a widget pushes a new parameter value *back to* Workspace. Workspace persists the update and re-sends it to every widget [grouped](../json-specs/apps-json-reference) on that parameter, so one widget can drive the rest of the dashboard.

0 commit comments

Comments
 (0)