Network sign-in with LinkSpin (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/linkspin hop for signed-in members' cross-site links; /sso/start (state cookie +
30-minute loop guard) -> LinkSpin /sso/check -> /sso/in?t=<v1 HMAC-SHA256 token, NETWORK_SSO_SECRET, 60 s, single-use nonce
(MySQL table network_sso_nonces when on the DB, else DATA_DIR file), bound to the browser's state cookie, email, audience and a
same-site relative path>. Member sessions only (admin portal never shared), ordinary 4-hour session, /my lands with ?welcome=1
so the login ad runs as after a code sign-in. An email with no account here or a waiting LinkSpin/BTC4Hits account gets the
normal email-code sign-in, email prefilled; nothing is created. Silent check on /my via public/assets/netsso.js
(/api/sso/status); never for bots/fetches; sign-out pauses it 12 hours. Engine Room + Fuel links go through /go/linkspin.
Chatbot knows it (KNOWLEDGE_DATE 2026-11-12). Off until NETWORK_SSO_SECRET (32+ chars) is set.

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:00:23 -06:00
parent 3eae242dc3
commit 5585abb663
10 changed files with 605 additions and 6 deletions
+25 -1
View File
@@ -17,6 +17,7 @@ const chain = require('./chain');
const auth = require('./auth');
const accounts = require('./accounts');
const forumsso = require('./forumsso'); // Earners Corner forum sign-in (DiscourseConnect, 2026-11-10)
const networksso = require('./networksso'); // network sign-in with LinkSpin (2026-11-12, Marty approved): see networksso.js
const themehead = require('./themehead'); // 2026-11-01 light/dark theme head script for server-rendered pages + its CSP hash
const ads = require('./ads');
const mailer = require('./mailer');
@@ -563,6 +564,27 @@ async function boot() {
}).catch(e => console.error('marks claim', e.message));
} });
auth.init({ dataDir: DATA_DIR, chain, isProd: IS_PROD, site: 'instantadpay.com' });
// network sign-in (2026-11-12): a member signed in on LinkSpin arrives here signed in, and the other way round. Member sessions
// only (the admin portal is never shared); an account that is not here yet, or is still a waiting LinkSpin/BTC4Hits account,
// gets the normal email-code sign-in with the email filled in, so every new-account check (anti-fraud, sponsor) runs as before.
networksso.init({ self: 'iap', peer: 'linkspin', peerBase: LS_BASE, isProd: IS_PROD, dataDir: DATA_DIR, db, defaultPath: '/my',
member: async req => { const s = await auth.fromRequest(req); return s && s.email && !fraud.isSuspended(s.email) ? s : null; },
accept: async email => {
const a = await accounts.byEmail(email);
if (!a) return { fallback: 'no account here yet' };
if (accounts.isUnclaimedShell(a)) return { fallback: 'waiting account, first sign-in needs the code' };
if (fraud.isSuspended(email) || fraud.isBlocked(email)) return { fallback: 'suspended or blocked' };
return { ok: true };
},
signIn: async (email, req) => { // 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) {} }
fraud.recordSeen(email, req).catch(() => {});
return auth.sessionCookie(await auth.mintSession({ email: a.email, address: a.address, memberId }));
},
// the dashboard runs the welcome tour / login ad after a sign-in (?welcome=1, the same step a code sign-in takes)
landing: to => { const x = new URL(to, 'http://x'); if (x.pathname === '/my') x.searchParams.set('welcome', '1'); return x.pathname + x.search + x.hash; },
signinPath: to => { const x = new URL(to, 'http://x'); return x.pathname === '/my' ? '/my' + x.hash : '/my'; } });
accounts.init({ dataDir: DATA_DIR });
ads.init({ dataDir: DATA_DIR, chain, tiers: () => geo.tierLists(siteConfig()) });
mailer.init({ dataDir: DATA_DIR });
@@ -2285,6 +2307,8 @@ const server = http.createServer(async (req, res) => {
const to = 'https://instantadpay.com' + (p === '/' ? '/' : ref ? '/join/' + ref[1] : p) + (u.search || '');
res.writeHead(302, { Location: to, 'Cache-Control': 'no-store', 'X-Robots-Tag': 'noindex' }); return res.end();
} }
// network sign-in with LinkSpin (2026-11-12): /go/linkspin, /sso/start, /sso/check, /sso/in, /api/sso/status
if (req.method === 'GET' && (p === '/go/linkspin' || p.startsWith('/sso/') || p === '/api/sso/status') && await networksso.handle(req, res, u)) return;
// a LinkSpin click arriving on any page (?lsclk= or ?lsid=): the first-party cookie, 30 days, last click wins (reporting only, lsreport.js).
// Added to whatever the page sends, like the viral-link cookies below.
@@ -2939,7 +2963,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 { return json(res, 200, await chain.suggestedFees()); }