
Some checks failed
CI - 4NK Node / Integration Tests (push) Failing after 9s
CI - 4NK Node / Docker Build & Test (push) Failing after 8s
CI - 4NK Node / Documentation Tests (push) Failing after 3s
CI - 4NK Node / Release Guard (push) Has been skipped
CI - 4NK Node / Performance Tests (push) Failing after 29s
CI - 4NK Node / Code Quality (push) Failing after 32s
CI - 4NK Node / Unit Tests (push) Failing after 30s
CI - 4NK Node / Security Tests (push) Failing after 28s
CI - 4NK Node / Notify (push) Failing after 1s
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
(function () {
|
||
const iframe = document.getElementById('ihm');
|
||
const logEl = document.getElementById('log');
|
||
const accessEl = document.getElementById('accessToken');
|
||
const refreshEl = document.getElementById('refreshToken');
|
||
const lastTypeEl = document.getElementById('lastType');
|
||
|
||
/**
|
||
* Logging util
|
||
*/
|
||
function log(line) {
|
||
const ts = new Date().toISOString();
|
||
logEl.textContent += `[${ts}] ${line}\n`;
|
||
logEl.scrollTop = logEl.scrollHeight;
|
||
}
|
||
|
||
/**
|
||
* Parent → iframe: envoi d’un message typé
|
||
*/
|
||
function sendToIframe(obj) {
|
||
if (!iframe || !iframe.contentWindow) {
|
||
log('iframe non prêt');
|
||
return;
|
||
}
|
||
iframe.contentWindow.postMessage(obj, window.origin);
|
||
}
|
||
|
||
/**
|
||
* Réception côté parent
|
||
*/
|
||
window.addEventListener('message', (event) => {
|
||
try {
|
||
const data = event.data || {};
|
||
if (!data || typeof data !== 'object') return;
|
||
if (!data.type) return;
|
||
lastTypeEl.value = String(data.type);
|
||
if (data.type === 'LINK_ACCEPTED') {
|
||
if (data.accessToken) accessEl.value = data.accessToken;
|
||
if (data.refreshToken) refreshEl.value = data.refreshToken;
|
||
}
|
||
log(`← ${JSON.stringify(data)}`);
|
||
} catch (e) {
|
||
log(`Erreur réception: ${String(e)}`);
|
||
}
|
||
});
|
||
|
||
/**
|
||
* Actions UI
|
||
*/
|
||
document.getElementById('btn-link').addEventListener('click', () => {
|
||
const msg = { type: 'REQUEST_LINK', messageId: 'host-req-1' };
|
||
log(`→ ${JSON.stringify(msg)}`);
|
||
sendToIframe(msg);
|
||
});
|
||
|
||
document.getElementById('btn-validate').addEventListener('click', () => {
|
||
const msg = { type: 'VALIDATE_TOKEN', accessToken: accessEl.value, refreshToken: refreshEl.value, messageId: 'host-val-1' };
|
||
log(`→ ${JSON.stringify(msg)}`);
|
||
sendToIframe(msg);
|
||
});
|
||
|
||
document.getElementById('btn-renew').addEventListener('click', () => {
|
||
const msg = { type: 'RENEW_TOKEN', refreshToken: refreshEl.value, messageId: 'host-renew-1' };
|
||
log(`→ ${JSON.stringify(msg)}`);
|
||
sendToIframe(msg);
|
||
});
|
||
})();
|
||
|
||
|