Skip to content

Commit d8f5ad2

Browse files
Merge pull request #1023 from akeneo/DXIM-1-JWT-in-uiext-iframe
DXIM-1 Add iframe secret management to doc
2 parents 6b4b27b + 834527e commit d8f5ad2

File tree

1 file changed

+77
-7
lines changed

1 file changed

+77
-7
lines changed

content/extensions/ui-extensions.md

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,87 @@ An iframe (inline frame) is an HTML element that allows you to embed another HTM
193193

194194
For more detailed information, you can refer to the [Mozilla Developer Network (MDN) documentation on iframes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe).
195195

196-
To ensure the secure embedding of iframes, it is essential to properly configure [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) headers to control the sources from which content can be loaded.
196+
To configure an `iframe` UI extension, mandatory fields are `name`, `position`, `type`, and `configuration`. Inside `configuration`, mandatory options are `default_label`, `secret` and `url`.
197+
198+
**Ensuring security of embedded iframes**
199+
200+
* Properly configure [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) headers to control the sources from which content can be loaded.
197201

198202
::: warning
199203
Please note that if these headers are misconfigured, iframe functionality may not work as intended.
200204
:::
201205

202-
To configure an `iframe` UI extension, mandatory fields are `name`, `position`, `type`, and `configuration`. Inside `configuration`, mandatory options are `default_label` and `url`.
206+
* Add a secret to your extension. This secret will be used to generate a JWT token when the iframe is loaded by the PIM system.
207+
208+
**Receiving the JWT Token via ```postMessage```**
209+
210+
First, from your iframe, you must request for the JWT by doing a PostMessage with a payload containing ```type: 'request_jwt'```
211+
212+
Example :
213+
```js
214+
window.parent.postMessage(
215+
{
216+
type: 'request_jwt'
217+
},
218+
"*"
219+
);
220+
```
221+
222+
the PIM will then answer with a postMessage containing the JWT token. The message will be structured as follows:
223+
224+
```json
225+
{
226+
"type": "JWT_TOKEN",
227+
"token": "jwt_value"
228+
}
229+
```
230+
231+
* The JWT token in the token field is generated using SHA256 encryption based on the secret you provided.
232+
233+
For more information on how JWT tokens are structured and used, you can refer to the associated [RFC 7519](https://datatracker.ietf.org/doc/html/rfc7519).
234+
235+
**JWT Token Structure**
236+
237+
The JWT token consists of three main parts: the header, the body (payload), and the signature.
238+
239+
*Header*
240+
241+
* The header typically contains information about the token type and the signing algorithm. In this case, it will look like:
242+
243+
```json
244+
{
245+
"typ": "JWT",
246+
"alg": "HS256"
247+
}
248+
```
249+
250+
*Payload*
251+
252+
* The payload contains the claims. The JWT token’s will look like this:
253+
254+
```json
255+
{
256+
"jti": "c1b6b9f1-8486-4f9e-9f96-8d1b40fccb65",
257+
"iat": 1743410036.116152,
258+
"exp": 1743413636.116162,
259+
"userId": "1"
260+
}
261+
```
262+
263+
* ```jti``` The unique identifier for the token.
264+
* ```iat``` The issued at time.
265+
* ```exp``` The expiration time of the token.
266+
* ```userId``` The PIM user identifier (in this case, ```1```).
267+
268+
*A signature*
269+
270+
* The signature is used to verify that the token is valid and has not been tampered with. It is generated by combining the encoded header and payload, and then signing them with the secret key. The resulting signature might look like:
271+
```9WBB7ayP8UnFrOlMrI9NzTj3kxaiXOWJzElyacEKt48```
272+
273+
**Verifying the Signature**
274+
275+
To ensure that the JWT token was issued by Akeneo, you can verify the signature by re-encoding the header and payload and then signing them using the same secret key. This will allow you to confirm that the token is valid and has not been altered.
276+
203277

204278
**PostMessage**
205279

@@ -272,7 +346,7 @@ An **action** UI extension is designed to perform external tasks in the backgrou
272346
+ **Notification on completion**: A notification will appear once the external server responds to the request, keeping users informed of the task's status.
273347
+ **Timeout**: The PIM HTTP client that communicates with the destination is configured with a timeout of 5 seconds.
274348
+ **POST HTTP method**: The request being sent to the destination is a POST request.
275-
+ **Signature**: It's possible to configure a [secret](#secret) to sign each request sent to the destination.
349+
+ **Signature**: It's possible to configure a `secret` to sign the body of the POST request sent to the destination (<a href='https://wikipedia.org/wiki/SHA-2'>SHA-512</a> protocol).
276350

277351
Here is a diagram illustrating the workflow:
278352
[![action-extension-schema.png](../img/extensions/ui-extensions/action-extension-schema.png)](../img/extensions/ui-extensions/action-extension-schema.png)
@@ -396,10 +470,6 @@ This position refers to the list of commands availables after selecting some pro
396470
For the moment, you can't use UI extensions with more than **500** selected products & product models.
397471
:::
398472

399-
### Secret
400-
A secret can be used for UI extensions of type `action`. If it is, this secret is used to sign (with <a href='https://wikipedia.org/wiki/SHA-2'>SHA-512</a> protocol) the body of the POST request sent to the destination.
401-
402-
403473
### Url
404474
All types of UI extensions must have a configured URL. However, the parameters that are sent—or can be sent—vary depending on the specific type of extension.
405475
#### Query parameters placeholders

0 commit comments

Comments
 (0)