Login page and Settings → eGov: relay session with a server-side challenge/nonce, QR + eGov Mobile deep link, polling, one-shot completion; IIN from the signer's certificate (own DER reader), users.egov_iin. The relay is trusted (PM decision): no own XMLDSig check. CLI peppa user egov, mock-kazeds-relay, tests. Dev mode: /_next/static is no-store (Cloudflare cached stale chunks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
2.1 KiB
JavaScript
34 lines
2.1 KiB
JavaScript
// Entirely local, test-only journey. The owner callback checks challenge
|
|
// plumbing but does NOT validate a real XML signature or authenticate anyone.
|
|
const express = require('express');
|
|
const { makeRouter } = require('./signWidget.server');
|
|
|
|
const app = express();
|
|
app.get('/', (_req, res) => res.type('html').send(`<!doctype html>
|
|
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>KazEDS local mock</title></head>
|
|
<body style="font:16px system-ui;max-width:540px;margin:40px auto;padding:16px"><h1>eGov widget mock journey</h1>
|
|
<p>Local UI test only. The signature is fabricated.</p><div id="egov-login"></div><p id="out" aria-live="polite"></p>
|
|
<script src="/signWidget.js"></script><script>
|
|
SignWidget.mount({container:'#egov-login',apiBase:'/api/egov-login',onSigned:async({verificationHandle})=>{
|
|
const r=await fetch('/api/egov-login/complete',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({verificationHandle})});
|
|
const data=await r.json();if(!r.ok)throw new Error(data.error||'Mock callback failed');
|
|
document.querySelector('#out').textContent=data.message;
|
|
},onError:(e)=>{document.querySelector('#out').textContent=e.message;}});
|
|
</script></body></html>`));
|
|
app.get('/signWidget.js', (_req, res) => res.sendFile(require('node:path').join(__dirname, 'signWidget.js')));
|
|
app.use('/api/egov-login', makeRouter({
|
|
onComplete: async ({ challenge, nonce, signedDocuments }) => {
|
|
const xml = signedDocuments?.[0]?.documentXml || '';
|
|
if (!xml.includes(`<challenge>${challenge}</challenge>`) || !xml.includes(`<nonce>${nonce}</nonce>`)) {
|
|
throw new Error('Mock challenge/nonce mismatch');
|
|
}
|
|
if (!xml.includes('<SignatureValue>NOT_A_SIGNATURE</SignatureValue>')) {
|
|
throw new Error('This demo expects the test mock response');
|
|
}
|
|
return { mockOnly: true, message: 'Challenge handoff passed; no signature was verified.' };
|
|
},
|
|
}));
|
|
|
|
const port = Number(process.env.PORT || 3102);
|
|
app.listen(port, '127.0.0.1', () => console.log(`TEST WIDGET ADAPTER ONLY at http://127.0.0.1:${port}`));
|