From 2e33136d88f7ac5dc45c37e1b9d85747853db557 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Thu, 29 Jan 2026 15:20:52 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=AE=20Add=20platform=20configuration?= =?UTF-8?q?=20for=20new=20gaming=20systems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokedex.online/src/config/platforms.js | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 code/websites/pokedex.online/src/config/platforms.js diff --git a/code/websites/pokedex.online/src/config/platforms.js b/code/websites/pokedex.online/src/config/platforms.js new file mode 100644 index 0000000..693a56f --- /dev/null +++ b/code/websites/pokedex.online/src/config/platforms.js @@ -0,0 +1,114 @@ +/** + * Platform Registry + * + * Centralized configuration for OAuth providers and authentication methods + * Supports: Challonge (OAuth, API Key, Client Credentials), Discord (OAuth) + * + * Add new platforms by extending PLATFORMS object with name, label, icon, and auth methods + */ + +export const PLATFORMS = { + challonge: { + name: 'challonge', + label: 'Challonge', + icon: '🏆', + description: 'Tournament management and API access', + helpUrl: 'https://challonge.com/settings/developer', + auth: { + apiKey: { + enabled: true, + label: 'API Key', + description: 'Direct API key authentication for v1 and v2.1', + storageKey: 'challonge_api_key' + }, + oauth: { + enabled: true, + label: 'OAuth 2.0', + description: 'User token authentication for v2.1 API', + endpoint: 'https://api.challonge.com/oauth/authorize', + tokenEndpoint: '/api/oauth/token', + refreshEndpoint: '/api/oauth/refresh', + scopes: ['tournaments:read', 'tournaments:write'], + storageKey: 'challonge_oauth_tokens' + }, + clientCredentials: { + enabled: true, + label: 'Client Credentials', + description: 'For APPLICATION scope access', + tokenEndpoint: 'https://api.challonge.com/oauth/token', + storageKey: 'challonge_client_credentials' + } + } + }, + discord: { + name: 'discord', + label: 'Discord', + icon: '🎮', + description: 'Personal identity verification and access control', + helpUrl: 'https://discord.com/developers/applications', + auth: { + oauth: { + enabled: true, + label: 'OAuth 2.0', + description: 'Verify your Discord identity', + endpoint: 'https://discord.com/api/oauth2/authorize', + tokenEndpoint: '/api/oauth/token', + refreshEndpoint: '/api/oauth/refresh', + scopes: ['identify'], + storageKey: 'discord_oauth_tokens', + userEndpoint: 'https://discord.com/api/users/@me' + } + } + } +}; + +/** + * Get platform configuration by name + * @param {string} name - Platform name (e.g., 'challonge', 'discord') + * @returns {Object} Platform configuration or throws error if not found + */ +export function getPlatform(name) { + const platform = PLATFORMS[name]; + if (!platform) { + throw new Error(`Platform not found: ${name}`); + } + return platform; +} + +/** + * Get all platforms + * @returns {Object[]} Array of all platform configurations + */ +export function getAllPlatforms() { + return Object.values(PLATFORMS); +} + +/** + * Check if a platform has a specific auth method + * @param {string} platformName - Platform name + * @param {string} methodName - Auth method name (e.g., 'oauth', 'apiKey') + * @returns {boolean} True if method is enabled + */ +export function hasAuthMethod(platformName, methodName) { + try { + const platform = getPlatform(platformName); + return platform.auth[methodName]?.enabled === true; + } catch { + return false; + } +} + +/** + * Get auth method configuration + * @param {string} platformName - Platform name + * @param {string} methodName - Auth method name + * @returns {Object} Auth method configuration + */ +export function getAuthMethod(platformName, methodName) { + const platform = getPlatform(platformName); + const method = platform.auth[methodName]; + if (!method || !method.enabled) { + throw new Error(`Auth method not found: ${platformName}.${methodName}`); + } + return method; +}