🔄 Refine authentication logic to prioritize tokens based on scope and improve debug configuration usage

This commit is contained in:
2026-01-28 18:41:04 +00:00
parent f25bbb3b2d
commit 68777f3596

View File

@@ -420,30 +420,51 @@ const client = computed(() => {
return createChallongeV1Client(apiKey.value); return createChallongeV1Client(apiKey.value);
} else { } else {
// v2.1 supports OAuth, client credentials, and API key // v2.1 supports OAuth, client credentials, and API key
// Priority: OAuth/Client Credentials > API Key // Smart priority based on scope selection:
// Note: Client credentials are OAuth tokens with APPLICATION scope permissions // - APPLICATION scope: prefer client credentials (they're designed for this)
if (isClientCredsAuthenticated.value && clientCredsToken.value) { // - USER scope: prefer OAuth user tokens or API key (client creds don't work well here)
// Use client credentials token (supports APPLICATION scope)
console.log('🔐 Using Client Credentials token'); if (tournamentScope.value === ScopeType.APPLICATION) {
return createChallongeV2Client( // APPLICATION scope - prefer client credentials
{ token: clientCredsToken.value, type: AuthType.OAUTH }, if (isClientCredsAuthenticated.value && clientCredsToken.value) {
{ debug: true } console.log('🔐 Using Client Credentials token for APPLICATION scope');
); return createChallongeV2Client(
} else if (isAuthenticated.value && accessToken.value) { { token: clientCredsToken.value, type: AuthType.OAUTH },
// Use OAuth token if authenticated (USER scope) { debug: debugMode.value }
console.log('🔐 Using OAuth token'); );
return createChallongeV2Client( } else if (isAuthenticated.value && accessToken.value) {
{ token: accessToken.value, type: AuthType.OAUTH }, console.log('🔐 Using OAuth user token for APPLICATION scope');
{ debug: true } return createChallongeV2Client(
); { token: accessToken.value, type: AuthType.OAUTH },
} else if (apiKey.value) { { debug: debugMode.value }
// Fall back to API key (USER scope only) );
console.log('🔑 Using API Key'); }
} else {
// USER scope - prefer OAuth user tokens or API key (client creds may not work)
if (isAuthenticated.value && accessToken.value) {
console.log('🔐 Using OAuth user token for USER scope');
return createChallongeV2Client(
{ token: accessToken.value, type: AuthType.OAUTH },
{ debug: debugMode.value }
);
} else if (apiKey.value) {
console.log('🔑 Using API Key for USER scope');
return createChallongeV2Client(
{ token: apiKey.value, type: AuthType.API_KEY },
{ debug: debugMode.value }
);
}
}
// Fallback: try API key
if (apiKey.value) {
console.log('🔑 Using API Key (fallback)');
return createChallongeV2Client( return createChallongeV2Client(
{ token: apiKey.value, type: AuthType.API_KEY }, { token: apiKey.value, type: AuthType.API_KEY },
{ debug: true } { debug: debugMode.value }
); );
} }
return null; return null;
} }
}); });