ci: docker_tag=ext feat(ihm): callback bridge authorized-client.html
All checks were successful
Build and Push Docker image (ext) / docker (push) Successful in 57s
All checks were successful
Build and Push Docker image (ext) / docker (push) Successful in 57s
This commit is contained in:
parent
b9f435c2bf
commit
3e53ed70d1
@ -1 +1,5 @@
|
||||
BOOTSTRAPURL=https://dev4.4nkweb.com/ws/
|
||||
|
||||
# ===================== /!\ donnée sensible =======================
|
||||
|
||||
VITE_JWT_SECRET_KEY=
|
103
public/authorized-client.html
Normal file
103
public/authorized-client.html
Normal file
@ -0,0 +1,103 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Redirection en cours…</title>
|
||||
<style>
|
||||
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 2rem; color: #0a0a0a; }
|
||||
.box { max-width: 720px; margin: 10vh auto; padding: 1.5rem; border: 1px solid #e5e7eb; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
|
||||
.muted { color: #6b7280; font-size: .95rem; }
|
||||
.error { color: #b91c1c; }
|
||||
.ok { color: #065f46; }
|
||||
code { background: #f3f4f6; padding: .2rem .35rem; border-radius: 6px; }
|
||||
a { color: #006BE0; text-decoration: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<h1>Connexion IdNot</h1>
|
||||
<p class="muted" id="status">Traitement du code d'autorisation…</p>
|
||||
<pre class="muted" id="details" style="white-space: pre-wrap"></pre>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
function getQueryParam(name) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
function setCookie(name, value, days) {
|
||||
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
||||
// Domaine implicite: dev4.4nkweb.com (hébergement de cette page)
|
||||
document.cookie = name + '=' + encodeURIComponent(value) + '; Path=/; Expires=' + expires + '; SameSite=None; Secure';
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const code = getQueryParam('code');
|
||||
const statusEl = document.getElementById('status');
|
||||
const detailsEl = document.getElementById('details');
|
||||
|
||||
if (!code) {
|
||||
statusEl.textContent = 'Aucun code reçu dans la redirection IdNot.';
|
||||
statusEl.className = 'error';
|
||||
detailsEl.textContent = 'Paramètre attendu: ?code=…\nRetour à l\'espace: https://dev4.4nkweb.com/lecoffre/';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const resp = await fetch('https://dev4.4nkweb.com/api/v1/idnot/auth', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Request-ID': 'bridge_' + Math.random().toString(36).slice(2)
|
||||
},
|
||||
body: JSON.stringify({ code })
|
||||
});
|
||||
|
||||
const text = await resp.text();
|
||||
let data;
|
||||
try { data = JSON.parse(text); } catch (_) { data = null; }
|
||||
|
||||
if (!resp.ok) {
|
||||
statusEl.textContent = 'Connexion refusée (' + resp.status + ').';
|
||||
statusEl.className = 'error';
|
||||
detailsEl.textContent = (data && data.error && data.error.message) ? data.error.message : text;
|
||||
// Redirige néanmoins vers le front avec état d\'erreur afin d\'afficher un message utilisateur.
|
||||
setTimeout(function(){ location.replace('https://dev4.4nkweb.com/lecoffre/authorized-bridge#error=' + encodeURIComponent(String(resp.status))); }, 600);
|
||||
return;
|
||||
}
|
||||
|
||||
// Attendu: { idNotUser, authToken }
|
||||
if (!data || !data.authToken) {
|
||||
statusEl.textContent = 'Réponse invalide du serveur.';
|
||||
statusEl.className = 'error';
|
||||
detailsEl.textContent = text;
|
||||
setTimeout(function(){ location.replace('https://dev4.4nkweb.com/lecoffre/authorized-bridge#error=invalid_response'); }, 800);
|
||||
return;
|
||||
}
|
||||
|
||||
// Stocker le jeton pour le domaine dev4 (utilisé par le front)
|
||||
setCookie('leCoffreAccessToken', data.authToken, 1);
|
||||
|
||||
statusEl.textContent = 'Connexion réussie, redirection…';
|
||||
statusEl.className = 'ok';
|
||||
detailsEl.textContent = '';
|
||||
|
||||
// Redirection vers le front avec token en hash en sauvegarde
|
||||
location.replace('https://dev4.4nkweb.com/lecoffre/authorized-bridge#token=' + encodeURIComponent(data.authToken));
|
||||
} catch (e) {
|
||||
statusEl.textContent = 'Erreur réseau lors de la connexion.';
|
||||
statusEl.className = 'error';
|
||||
detailsEl.textContent = String(e && e.message || e);
|
||||
setTimeout(function(){ location.replace('https://dev4.4nkweb.com/lecoffre/authorized-bridge#error=network'); }, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user