PolyWarriors hookups: in-game sign-in (game 'polywarriors', PW_SSO_SECRET), one-tap /api/my/polywarriors, sign-in return route
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1323,6 +1323,12 @@ function swOpen(token) {
|
|||||||
return { ok: true, claims: c };
|
return { ok: true, claims: c };
|
||||||
}
|
}
|
||||||
const swIsGameUrl = u => [SW_URL()].concat(SW_ALT()).some(o => String(u || '').startsWith(o + '/'));
|
const swIsGameUrl = u => [SW_URL()].concat(SW_ALT()).some(o => String(u || '').startsWith(o + '/'));
|
||||||
|
// -- PolyWarriors (2026-10-05): the cyberpunk fighting game at polywarriors.com; its own secret PW_SSO_SECRET (also on the game)
|
||||||
|
const PW_SECRET = () => String(process.env.PW_SSO_SECRET || '').trim();
|
||||||
|
const PW_URL = () => String(process.env.PW_URL || 'https://polywarriors.com').replace(/\/+$/, '');
|
||||||
|
const PW_ALT = () => String(process.env.PW_ALT_URLS || 'https://www.polywarriors.com,https://polywarriors.saasy.top').split(',').map(x => x.trim().replace(/\/+$/, '')).filter(Boolean);
|
||||||
|
const pwSign = p => drB64u(crypto.createHmac('sha256', PW_SECRET()).update(p).digest());
|
||||||
|
function pwMint(claims, ttlMs) { const payload = JSON.stringify(Object.assign({ iat: Date.now(), exp: Date.now() + (ttlMs || 300000), nonce: crypto.randomBytes(12).toString('hex') }, claims)); return drB64u(payload) + '.' + pwSign(payload); }
|
||||||
async function swCallback(cbUrl, receipt) {
|
async function swCallback(cbUrl, receipt) {
|
||||||
if (!swIsGameUrl(cbUrl)) return false;
|
if (!swIsGameUrl(cbUrl)) return false;
|
||||||
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('spellwheel callback', e.message); return false; }
|
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('spellwheel callback', e.message); return false; }
|
||||||
@@ -1493,6 +1499,8 @@ const GAME_AUTH = {
|
|||||||
mint: (a, memberId) => seekMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
mint: (a, memberId) => seekMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||||
spellwheel: { name: 'SpellWheel', origins: () => [SW_URL()].concat(SW_ALT()), host: () => SW_URL().replace(/^https?:\/\//, ''),
|
spellwheel: { name: 'SpellWheel', origins: () => [SW_URL()].concat(SW_ALT()), host: () => SW_URL().replace(/^https?:\/\//, ''),
|
||||||
mint: (a, memberId) => swMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
mint: (a, memberId) => swMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||||
|
polywarriors: { name: 'PolyWarriors', origins: () => [PW_URL()].concat(PW_ALT()), host: () => PW_URL().replace(/^https?:\/\//, ''),
|
||||||
|
mint: (a, memberId) => pwMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||||
gemkingdom: { name: 'Gem Kingdom', origins: () => [GK_URL(), 'https://gemkingdom.saasy.top'], host: () => GK_URL().replace(/^https?:\/\//, ''),
|
gemkingdom: { name: 'Gem Kingdom', origins: () => [GK_URL(), 'https://gemkingdom.saasy.top'], host: () => GK_URL().replace(/^https?:\/\//, ''),
|
||||||
mint: (a, memberId) => gkMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
mint: (a, memberId) => gkMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||||
};
|
};
|
||||||
@@ -1902,7 +1910,7 @@ const server = http.createServer(async (req, res) => {
|
|||||||
let memberId = 0;
|
let memberId = 0;
|
||||||
if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} }
|
if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} }
|
||||||
const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId });
|
const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId });
|
||||||
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
|
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', polywarriors: '/api/my/polywarriors', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies.
|
// -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies.
|
||||||
@@ -2815,6 +2823,15 @@ const server = http.createServer(async (req, res) => {
|
|||||||
sponsorRef: (acct && acct.sponsorRef) || null, joinedRef: (acct && acct.joinedRef) || null, joinedAt: (acct && acct.created) || null }); // the game credits referrals to the IAP sponsor
|
sponsorRef: (acct && acct.sponsorRef) || null, joinedRef: (acct && acct.joinedRef) || null, joinedAt: (acct && acct.created) || null }); // the game credits referrals to the IAP sponsor
|
||||||
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
|
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
|
||||||
}
|
}
|
||||||
|
// -- PolyWarriors hand-off (2026-10-05): sign the member across; the game verifies with PW_SSO_SECRET
|
||||||
|
if (p === '/api/my/polywarriors' && req.method === 'GET') {
|
||||||
|
const s = await auth.fromRequest(req);
|
||||||
|
if (!s || !s.email) { res.writeHead(302, { Location: '/my', 'Set-Cookie': gkCookie('iap.return', 'polywarriors', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
|
||||||
|
if (PW_SECRET().length < 32) return json(res, 503, { error: 'PolyWarriors is not connected yet.' });
|
||||||
|
const acct = await accounts.byEmail(s.email);
|
||||||
|
const tok = pwMint({ memberId: Number((acct && acct.memberId) || s.memberId || 0), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null });
|
||||||
|
res.writeHead(302, { Location: PW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
|
||||||
|
}
|
||||||
// -- SpellWheel hand-off (2026-10-04): sign the member across; the game verifies with SW_SSO_SECRET
|
// -- SpellWheel hand-off (2026-10-04): sign the member across; the game verifies with SW_SSO_SECRET
|
||||||
if (p === '/api/my/spellwheel' && req.method === 'GET') {
|
if (p === '/api/my/spellwheel' && req.method === 'GET') {
|
||||||
const s = await auth.fromRequest(req);
|
const s = await auth.fromRequest(req);
|
||||||
|
|||||||
Reference in New Issue
Block a user