Earners Corner forum sign-in (Marty 2026-11-10): InstantAdPay is the DiscourseConnect identity provider for earnerscorner.com. /forum/sso verifies Discourse's HMAC-signed request (return URL must be on the forum), a signed-out visitor signs in on /my (request kept in a 30-minute cookie, my.js hands back via /api/my/forum), then a signed payload goes back: email, external id, username, Stack POL page as website, groups network_members (on-chain position) and wallet_linked. Suspended accounts are refused. Env FORUM_SSO_SECRET + FORUM_URL. qa/forumsso.mjs 9/9; member walk 0 bugs; my.js ?v=20261110forum.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
// Earners Corner forum sign-in (Marty 2026-11-10): earnerscorner.com runs Discourse with DiscourseConnect, and InstantAdPay is the
|
||||
// identity provider, so every forum name is a real InstantAdPay account (no separate forum sign-ups to farm). Discourse sends
|
||||
// /forum/sso?sso=<base64 payload>&sig=<hex HMAC-SHA256>; we check the signature, make sure the visitor is signed in here, and send
|
||||
// back a signed payload with the member's email, username and groups. Secret: env FORUM_SSO_SECRET (the same value is set in
|
||||
// Discourse as discourse_connect_secret). Groups: network_members (paying member: an on-chain position) and wallet_linked; in
|
||||
// Discourse those groups grant the trust level that may post links, so link spam needs a real member behind it.
|
||||
'use strict';
|
||||
const crypto = require('crypto');
|
||||
|
||||
const SECRET = () => String(process.env.FORUM_SSO_SECRET || '').trim();
|
||||
const FORUM_URL = () => String(process.env.FORUM_URL || 'https://earnerscorner.com').replace(/\/+$/, '');
|
||||
const sign = s => crypto.createHmac('sha256', SECRET()).update(s).digest('hex');
|
||||
|
||||
// -> { nonce, returnUrl } or { error }
|
||||
function verify(sso, sig) {
|
||||
if (SECRET().length < 32) return { error: 'The forum sign-in is not connected yet.' };
|
||||
sso = String(sso || ''); sig = String(sig || '').toLowerCase();
|
||||
if (!sso || !/^[0-9a-f]{64}$/.test(sig)) return { error: 'That forum sign-in link is incomplete.' };
|
||||
const want = Buffer.from(sign(sso), 'hex'), got = Buffer.from(sig, 'hex');
|
||||
if (want.length !== got.length || !crypto.timingSafeEqual(want, got)) return { error: 'That forum sign-in link is not valid.' };
|
||||
const q = new URLSearchParams(Buffer.from(sso, 'base64').toString('utf8'));
|
||||
const nonce = q.get('nonce'), returnUrl = q.get('return_sso_url') || '';
|
||||
if (!nonce) return { error: 'That forum sign-in link is incomplete.' };
|
||||
if (!returnUrl.startsWith(FORUM_URL() + '/')) return { error: 'That forum sign-in link points somewhere else.' };
|
||||
return { nonce, returnUrl };
|
||||
}
|
||||
|
||||
// the signed redirect back to the forum for this account
|
||||
function redirectFor(v, acct, site) {
|
||||
const email = String(acct.email || '').toLowerCase();
|
||||
const groups = [];
|
||||
if (Number(acct.memberId) > 0) groups.push('network_members');
|
||||
if (acct.address) groups.push('wallet_linked');
|
||||
const p = new URLSearchParams({ nonce: v.nonce, email, external_id: email, require_activation: 'false', suppress_welcome_message: 'false' });
|
||||
if (acct.username) { p.set('username', acct.username); p.set('name', acct.username); }
|
||||
if (acct.avatarUrl) p.set('avatar_url', /^https?:/.test(acct.avatarUrl) ? acct.avatarUrl : site + acct.avatarUrl);
|
||||
if (acct.username) p.set('website', 'https://stackpol.com/' + acct.username);
|
||||
if (groups.length) p.set('add_groups', groups.join(','));
|
||||
const remove = ['network_members', 'wallet_linked'].filter(g => !groups.includes(g)); if (remove.length) p.set('remove_groups', remove.join(','));
|
||||
const out = Buffer.from(p.toString()).toString('base64');
|
||||
return v.returnUrl + (v.returnUrl.includes('?') ? '&' : '?') + 'sso=' + encodeURIComponent(out) + '&sig=' + sign(out);
|
||||
}
|
||||
|
||||
module.exports = { verify, redirectFor, sign, SECRET, FORUM_URL };
|
||||
Reference in New Issue
Block a user