๐ Fort Knox Security Implementation
External Scrabble Game Authentication System
โ
Security Implemented! Your external Scrabble game now uses military-grade JWT authentication with HMAC-SHA256 signatures, rate limiting, and 5-minute token expiry.
How It Works
1
User clicks "Scrabble" โ System generates secure JWT token with their email, premium status, and pearl balance
2
Token is signed with HMAC-SHA256 using JWT_SECRET (expires in 5 minutes)
3
User redirected to external game with token in URL: ?auth=eyJhbGc...
4
External game validates token via /gameAPISupabase?endpoint=validate
5
On success, game receives user data and can award pearls using existing HMAC-signed API
Security Features Implemented
- โ JWT Tokens: Short-lived (5 min), cryptographically signed
- โ HMAC-SHA256: Prevents token tampering or forgery
- โ Rate Limiting: Max 10 tokens per minute per user
- โ Expiration Check: Tokens auto-expire after 5 minutes
- โ Nonce Protection: Prevents replay attacks
- โ IP Logging: Tracks request origin for fraud detection
- โ No Email in URL: Sensitive data only in signed token payload
External Game Integration Code
Share this with your external Scrabble game developer (idioms-scrabble-language.deploypad.app)
// External Game: Validate Token on Load
// In your idioms-scrabble-language.deploypad.app app
async function authenticateUser() {
// Extract token from URL
const params = new URLSearchParams(window.location.search);
const token = params.get('auth');
if (!token) {
alert('Please launch from Snappy Idioms');
return null;
}
// Validate with Mothership
try {
const response = await fetch(
'https://snappyidioms.com/functions/gameAPISupabase?endpoint=validate',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Game-ID': 'famous_scrabble_01',
'X-Timestamp': Date.now().toString(),
'X-Nonce': crypto.randomUUID(),
'X-Signature': 'not_required_for_validation'
},
body: JSON.stringify({ token })
}
);
const result = await response.json();
if (result.valid) {
// User authenticated!
console.log('User:', result.user.email);
console.log('Pearl Balance:', result.user.pearlBalance);
console.log('Premium:', result.user.isPremium);
return result.user;
} else {
alert('Authentication failed: ' + result.error);
return null;
}
} catch (error) {
console.error('Auth error:', error);
alert('Failed to authenticate. Please try again.');
return null;
}
}
// On game load:
const user = await authenticateUser();
if (!user) {
// Redirect back to Snappy Idioms login
window.location.href = 'https://snappyidioms.com';
}
// Store user data for pearl reporting
window.currentUser = user;๐ฎ Reporting Pearl Rewards
After validating the token, use the existing HMAC-signed API to award pearls:
// When game completes:
import { reportCompletion } from './lib/mothership-sdk';
const result = await reportCompletion(
window.currentUser.email,
roundNumber,
finalScore,
completedIdioms
);
if (result.success) {
console.log(`Earned ${result.pearlsAwarded} pearls!`);
showRewardUI(result.pearlsAwarded);
}๐ Setup Checklist:
- โ JWT_SECRET added to environment secrets
- โ generateGameToken function deployed
- โ gameAPISupabase updated with /validate endpoint
- โ GamesHub auto-generates tokens on Scrabble click
- โณ External game needs to implement authenticateUser() on load
- โณ External game needs to use existing reportCompletion() for pearls