Skip to content

Commit 985e2c2

Browse files
committed
Added code snippets from Frontend side
1 parent 5f1bb2b commit 985e2c2

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

docs/quix-cloud/managed-services/plugin.md

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ The plugin system enables services to expose an embedded UI inside Deployment De
44

55
Managed services may populate these plugin properties automatically via the Managed Framework, and you can always override them explicitly in YAML.
66

7-
Nonmanaged services can also define these properties in YAML, making any deployment behave like a plugin without being a managed service.
7+
Non-managed services can also define these properties in YAML, making any deployment behave like a plugin without being a managed service.
88

99
## What it does
1010

11-
- Embed a UI in Deployment Details when enabled
11+
* Embed a UI in Deployment Details when enabled
1212

1313
![Embedded View](images/dynamic-configuration-embedded-view.png){width=80%}
1414

15-
- Optionally show a sidebar shortcut to the embedded view
15+
* Optionally show a sidebar shortcut to the embedded view
1616

1717
![Sidebar example](images/plugin-sidebar.png){height=50%}
1818

19-
- Provide basic authentication integration with Quix Cloud so publicly exposed services don’t require a separate login
19+
* Provide basic authentication integration with Quix Cloud so publicly exposed services don’t require a separate login
2020

2121
## YAML configuration
2222

@@ -34,17 +34,17 @@ plugin:
3434
3535
Notes
3636
37-
- plugin.embeddedView: boolean. true → FE renders embedded UI.
38-
- plugin.sidebarItem: optional object configuring the Environment’s left sidebar item.
37+
* plugin.embeddedView: boolean. true → FE renders embedded UI.
38+
* plugin.sidebarItem: optional object configuring the Environment’s left sidebar item.
3939
4040
## Embedded view URL
4141
4242
When the plugin feature is enabled, the deployment exposes a public URL dedicated to the embedded UI. The Portal uses this URL to load the embedded view inside the iframe when `embeddedView` is enabled. This URL is not set in YAML; it’s exposed by the API.
4343

4444
Population rules:
4545

46-
- Managed service → Derived from Managed Services conventions.
47-
- Nonmanaged service → Requires `publicAccess` to be enabled; resolves from the deployment’s public URL.
46+
* Managed service → Derived from Managed Services conventions.
47+
* Non-managed service → Requires `publicAccess` to be enabled; resolves from the deployment’s public URL.
4848

4949
## Authentication and authorization
5050

@@ -55,6 +55,61 @@ When an embedded view loads, the Plugin system injects the Quix user token into
5555

5656
On initial load of the embedded view (and on reload), the Portal provides the user token to the iframe so the UI can authenticate calls to the backend.
5757

58+
#### Frontend token exchange (postMessage)
59+
60+
The token is passed via `window.postMessage` between the parent (Portal) and the embedded iframe.
61+
62+
**Message types**
63+
64+
* `REQUEST_AUTH_TOKEN` — sent by the iframe to ask the parent for a token
65+
* `AUTH_TOKEN` — sent by the parent with `{ token: string }`
66+
67+
**In the embedded view (iframe)**
68+
69+
```ts
70+
// Ask the parent window (Portal) for a token
71+
window.parent.postMessage({ type: 'REQUEST_AUTH_TOKEN' }, '*');
72+
73+
// Listen for the token response from the parent
74+
function messageHandler(event: MessageEvent) {
75+
const { data } = event;
76+
if (data?.type === 'AUTH_TOKEN' && data.token) {
77+
// Your app-specific setter
78+
setToken(data.token);
79+
// Optionally remove the listener if you only need the token once
80+
// window.removeEventListener('message', messageHandler);
81+
}
82+
}
83+
84+
window.addEventListener('message', messageHandler);
85+
```
86+
87+
**In the Portal (parent window)**
88+
89+
```ts
90+
// Listen for requests from the target iframe
91+
function messageHandler(event: MessageEvent) {
92+
const { origin, data } = event;
93+
94+
// Ensure the origin matches the iframe URL you expect
95+
if (origin !== targetUrl) return;
96+
97+
if (data?.type === 'REQUEST_AUTH_TOKEN') {
98+
// Reply with the token to the requesting iframe
99+
const iframeWindow = deploymentIframe?.contentWindow;
100+
iframeWindow?.postMessage({ type: 'AUTH_TOKEN', token }, targetUrl);
101+
}
102+
}
103+
104+
window.addEventListener('message', messageHandler);
105+
```
106+
107+
**Security notes**
108+
109+
* Always validate `event.origin` in the parent before responding.
110+
* Prefer using a specific `targetUrl` over `'*'` when posting back to the iframe.
111+
* Remove listeners when no longer needed to avoid leaks.
112+
58113
### How to handle the token in the backend
59114

60115
Install the Quix Portal helper package from the public feed:
@@ -66,9 +121,7 @@ pip install -i https://pkgs.dev.azure.com/quix-analytics/53f7fe95-59fe-4307-b479
66121
Then, in the backend service, validate the token and enforce authorization for each request. For example:
67122

68123
```python
69-
70124
import os
71-
72125
from quixportal.auth import Auth
73126
74127
# Instantiate authentication client. By default it will read
@@ -94,5 +147,4 @@ if auth.validate_permissions(
94147
print("Bearer is authorized to access the resource")
95148
else:
96149
print("Bearer is not authorized to access the resource")
97-
98150
```

0 commit comments

Comments
 (0)