Network sign-in with InstantAdPay (Marty approved 2026-11-12): signed in on one site = signed in on the other, no email code

networksso.js (same file in both repos): /go/iap hop for signed-in members' cross-site links; /sso/start (state cookie +
30-minute loop guard) -> InstantAdPay /sso/check -> /sso/in?t=<v1 HMAC-SHA256 token, NETWORK_SSO_SECRET, 60 s, single-use nonce,
bound to the browser's state cookie, email, audience and a same-site relative path>. App host only (not link/pages hosts).
Member sessions only (admin portal never shared), ordinary 4-hour session. An email not here yet (sync not run) or not on
LS_TESTERS gets the normal email-code sign-in, email prefilled; nothing is created. Silent check on every Control Room screen
(cr-shell.js loads public/assets/netsso.js); never for bots/fetches; sign-out pauses it 12 hours. Engine Room, Fuel and the
arrival strip's Back to InstantAdPay go through /go/iap. Chatbot knows it (KNOWLEDGE_DATE 2026-11-12). Off until
NETWORK_SSO_SECRET (32+ chars) is set. ?v= bumped (cr-shell, fuel, engine-room: 20261112sso).

qa: networksso.test.cjs all passed, networksso.e2e.mjs (both servers, real browser) 31/31, run.sh member green (0 bugs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-12 07:05:51 -06:00
parent 3cc687aff5
commit e79d5ae63e
23 changed files with 618 additions and 21 deletions
+22 -1
View File
@@ -15,6 +15,7 @@ const { URL } = require('url');
const chain = require('./chain');
const auth = require('./auth');
const accounts = require('./accounts');
const networksso = require('./networksso'); // network sign-in with InstantAdPay (2026-11-12, Marty approved): see networksso.js
const themehead = require('./themehead'); // 2026-11-01 light/dark theme head script for server-rendered pages
const ads = require('./ads');
const mailer = require('./mailer');
@@ -632,6 +633,24 @@ async function boot() {
if (ev && ev.type === 'Purchase' && ev.buyerId) accounts.byMemberId(Number(ev.buyerId)).then(a => { if (a) return postbacks.convertFor(a.email, 'purchase', { payout: (Number(ev.priceCents) || 0) / 100, currency: 'USD', txid: ev.tx || '' }); }).catch(() => {});
if (ev && ev.type === 'Purchase') refuel.onPurchase(ev).catch(e => console.error('refuel report', e.message)); } }); // no-op while refuelStreak is off
auth.init({ dataDir: DATA_DIR, chain, isProd: IS_PROD, site: SITE_HOST });
// network sign-in (2026-11-12): a member signed in on InstantAdPay arrives here signed in, and the other way round. Member
// sessions only (the admin portal is never shared). An email that is not here yet (the 2-minute sync has not run) or is not
// let in (LS_TESTERS) gets the normal email-code sign-in with the email filled in; nothing is created by the network sign-in.
networksso.init({ self: 'linkspin', peer: 'iap', peerBase: IAP_BASE, isProd: IS_PROD, dataDir: DATA_DIR, db, defaultPath: '/ads',
member: async req => { const s = await auth.fromRequest(req); return s && s.email ? s : null; },
accept: async email => {
const a = await accounts.byEmail(email);
if (!a) return { fallback: 'no account here yet' };
if (!isTester(email, a)) return { fallback: 'not on the tester list' };
return { ok: true };
},
signIn: async email => { // the same session the email code makes (4 hours, same rights)
const a = await accounts.byEmail(email); let memberId = 0;
if (a && a.address) { try { memberId = await chain.memberIdByAccount(a.address); } catch (e) {} }
return auth.sessionCookie(await auth.mintSession({ email: a.email, address: a.address || null, memberId }));
},
landing: to => to,
signinPath: to => (to === '/' ? '/ads' : to) }); // every Control Room screen shows the sign-in itself
accounts.init({ dataDir: DATA_DIR });
ads.init({ dataDir: DATA_DIR, chain });
mailer.init({ dataDir: DATA_DIR });
@@ -1397,6 +1416,8 @@ const server = http.createServer(async (req, res) => {
const zonePath = p === '/z.js' || p === '/z/nas' || p === '/p.js' || p === '/p.gif' || p === '/t.js' || p === '/t.gif' || p === '/cv.gif' || p === '/cv.js' || p.startsWith('/u/pages/') || p.startsWith('/api/zone/') || p.startsWith('/banners/linkspin-') || p.startsWith('/art/house-') || /^\/(i|c|s)\/[a-z0-9]{5,12}(\.gif|\.js)?$/.test(p); // + Banner Spin image / click / script (2026-10-18)
// support must reach everyone, invited or not (2026-10-16): someone locked out or not yet let in is exactly who needs it
if (!zonePath && !supportOpen(p) && curtained(req, res, u)) return; // nothing below this line runs for an uninvited visitor
// network sign-in with InstantAdPay (2026-11-12): /go/iap, /sso/start, /sso/check, /sso/in, /api/sso/status (app host only)
if (req.method === 'GET' && (p === '/go/iap' || p.startsWith('/sso/') || p === '/api/sso/status') && !isPagesHost(req) && !isLinkHost(req) && await networksso.handle(req, res, u)) return;
// -- the rotator redirect: one hop, recorded, on any host (LinkSpin)
let rm = /^\/r\/([a-z0-9]{4,12})$/i.exec(p);
@@ -2019,7 +2040,7 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/auth/logout' && req.method === 'POST') {
await auth.logout(req);
return json(res, 200, { ok: true }, { 'Set-Cookie': auth.clearCookie() });
return json(res, 200, { ok: true }, { 'Set-Cookie': [auth.clearCookie(), networksso.offCookie()] }); // signed out stays signed out: no silent network sign-in here for 12 hours
}
if (p === '/api/gas' && req.method === 'GET') {
try {