# KazEDS eGov sign-in widget This integration asks eGov Mobile to sign a short-lived XML challenge and gives the signed XML to the relying website. The website owns signature verification and the login decision. ## Install the backend adapter Copy `signWidget.server.js` into the site's Node backend and install: ```sh npm install express qrcode ``` Mount it in an existing Express app: ```js const { makeRouter } = require('./signWidget.server'); app.use('/api/egov-login', makeRouter({ onComplete: async ({ challenge, nonce, signedDocuments, request }) => { // Implement with YOUR XMLDSig verifier and account policy. // 1. Verify the signature over the returned XML. // 2. Confirm the signed XML contains this exact challenge and nonce. // 3. Validate the certificate chain, validity and revocation. // 4. Resolve/link the account and create YOUR site's session. // `challenge` and `nonce` come from server memory, not the browser. const identity = await verifyEgovLogin({ challenge, nonce, signedDocuments }); if (!identity) throw new Error('Invalid eGov signature or challenge'); await createSiteSession(request, identity); return { authenticated: true }; }, })); ``` Set `KAZEDS_RELAY_BASE` if needed (default `https://sign.aitu.uz/relay/v1`), plus `EGOV_ORGANISATION_NAME` and `EGOV_ORGANISATION_BIN` for the relying site. Use the registered business identity and eGov-approved domain details required for your integration. ## Add the browser widget Serve `signWidget.js` from the relying site and add: ```html
``` Implement `/api/egov-login/verify` on the relying site's backend. Verify the XMLDSig cryptographically, ensure the signed content contains the exact server-side challenge and nonce, check the certificate chain, validity and revocation, and only then map the certified identity to an account or ask the user to link/create one. Do not trust identity fields sent by the browser, and do not create a login session just because the widget reports `completed`. The adapter stores short-lived correlation state in memory and is suitable for a single-process integration prototype. For multiple backend instances, replace its `Map` with shared storage and bind each flow to the site's authenticated/CSRF-protected browser session. The eGov Relay session store is also currently in memory. ## Test mode The Relay's eGov routes are the real API shim, not a deployed mock signer. For local end-to-end UI testing, point `KAZEDS_RELAY_BASE` at a local mock implementing `POST /egov/sessions` and `GET /egov/:id/status`; have it return a completed sample XML document. Real signing still requires eGov Mobile and its domain allowlist. Never use a fabricated signature to grant an account login.