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