115 lines
3.4 KiB
JavaScript
115 lines
3.4 KiB
JavaScript
/**
|
|
* 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;
|
|
}
|