Network hub sign-in, step 3 (Marty 2026-11-15)
networksso.js (the same file on every network site): with HUB_SSO=on /sso/start asks the network hub, /sso/in takes the hub's h1. token (this site's HUB_SECRET, iss hub, aud linkspin, 60 s, single use, state cookie) and falls back once to the pairwise InstantAdPay check when the hub has nobody. networksso.page() on every GET of the main host: a signed-in member's page load tells the hub once (nsso.hp) and pings /v1/activity once a day, only while the hub answers /health. Sessions: SESSION_TTL_HOURS (168 = 7 days in production), renewed on use at most hourly; cookie 30 days, the server's sliding expiry decides. auth.endSessions. Sign out everywhere: POST /api/auth/logout-everywhere; the account menu's Sign out asks "Only LinkSpin or every network site"; cr-shell.js?v=20261115hub. hubsync: member.blocked and member.signedout end every session of that member here. Chatbot: a sign-in lasts 7 days and renews; the silent check is every 2 minutes. Tests: qa/networksso-hub.e2e.mjs (same file as InstantAdPay, in run.sh). qa sso: ALL PASSED; qa member: ALL PASSED (known warnings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,7 +60,9 @@ const J = {
|
||||
this.sessions.set(token, Object.assign({}, s, fields));
|
||||
this.save();
|
||||
},
|
||||
async drop(token) { this.sessions.delete(token); this.save(); }
|
||||
async drop(token) { this.sessions.delete(token); this.save(); },
|
||||
async renew(token) { const s = this.sessions.get(token); if (!s) return; s.expires = Date.now() + SESSION_TTL; s.issued = Date.now(); this.save(); },
|
||||
async dropBy(email, address) { let n = 0; for (const [t, s] of this.sessions) if ((email && s.email === email) || (address && String(s.address || '').toLowerCase() === address)) { this.sessions.delete(t); n++; } if (n) this.save(); return n; }
|
||||
};
|
||||
|
||||
// ---- MySQL session mode ----
|
||||
@@ -87,7 +89,9 @@ const D = {
|
||||
vals.push(token);
|
||||
await db.q('UPDATE sessions SET ' + sets.join(',') + ' WHERE token=?', vals);
|
||||
},
|
||||
async drop(token) { await db.q('DELETE FROM sessions WHERE token=?', [token]); }
|
||||
async drop(token) { await db.q('DELETE FROM sessions WHERE token=?', [token]); },
|
||||
async renew(token) { await db.q('UPDATE sessions SET expires=? WHERE token=?', [Date.now() + SESSION_TTL, token]); },
|
||||
async dropBy(email, address) { const r = await db.q('DELETE FROM sessions WHERE ' + (email && address ? 'email=? OR LOWER(address)=?' : email ? 'email=?' : 'LOWER(address)=?'), [email, address].filter(Boolean)); return Number(r.affectedRows || 0); }
|
||||
};
|
||||
const impl = () => db.enabled() ? D : J;
|
||||
|
||||
@@ -146,7 +150,7 @@ async function verifyChallenge(address, signature) {
|
||||
async function mintSession(fields) { return impl().mint(fields || {}); }
|
||||
async function updateSession(token, fields) { return impl().update(token, fields || {}); }
|
||||
function sessionCookie(token) {
|
||||
return `iap.sid=${encodeURIComponent(token)}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${SESSION_TTL / 1000}${IS_PROD ? '; Secure' : ''}`;
|
||||
return `iap.sid=${encodeURIComponent(token)}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${Math.max(SESSION_TTL / 1000, 30 * 86400)}${IS_PROD ? '; Secure' : ''}`; // the cookie outlives the session; the server's sliding expiry decides (2026-11-15)
|
||||
}
|
||||
function clearCookie() { return 'iap.sid=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0'; }
|
||||
// onSeen (2026-10-26): told the email + request of every resolved session (conversion tracking keeps the soft keys a member
|
||||
@@ -156,6 +160,9 @@ async function fromRequest(req) {
|
||||
const m = /(?:^|;\s*)iap\.sid=([^;]+)/.exec(req.headers.cookie || '');
|
||||
if (!m) return null;
|
||||
const s = await impl().get(decodeURIComponent(m[1]));
|
||||
// renewed on use (2026-11-15, the network hub era: sessions are SESSION_TTL_HOURS long, 168 = 7 days, and slide while the member
|
||||
// is active; the login ad keeps its own clock, loginadclock.js). At most one write an hour per session.
|
||||
if (s && Number(s.expires) && Number(s.expires) - Date.now() < SESSION_TTL - Math.min(3600000, SESSION_TTL / 4)) { try { await impl().renew(s.token || decodeURIComponent(m[1])); } catch (e) {} }
|
||||
if (s && s.email && seenFn) { try { seenFn(s.email, req); } catch (e) {} }
|
||||
return s;
|
||||
}
|
||||
@@ -180,4 +187,5 @@ async function logout(req) {
|
||||
if (s) await impl().drop(s.token);
|
||||
}
|
||||
|
||||
module.exports = { init, makeChallenge, verifyChallenge, mintSession, updateSession, sessionCookie, clearCookie, fromRequest, onSeen, refreshMemberId, logout };
|
||||
async function endSessions(email, address) { return impl().dropBy(email ? String(email).toLowerCase() : null, address ? String(address).toLowerCase() : null); } // hub: blocked, erased, signed out everywhere
|
||||
module.exports = { endSessions, init, makeChallenge, verifyChallenge, mintSession, updateSession, sessionCookie, clearCookie, fromRequest, onSeen, refreshMemberId, logout };
|
||||
|
||||
Reference in New Issue
Block a user