refactor: derive auth-provider login options from SDK data instead of hardcoded provider lists

This commit is contained in:
Federico Jaramillo Martinez
2026-07-17 22:57:33 +02:00
parent f539193c3d
commit 910c6b5ae0
3 changed files with 19 additions and 22 deletions
@@ -1,7 +1,5 @@
import type { AuthProviderOption, AuthProviderStatus, AuthType } from "../../shared/apiTypes.js";
const OAUTH_ONLY_PROVIDERS = new Set(["github-copilot", "openai-codex"]);
/** Minimal provider shape needed to enumerate login/logout options. */
interface AuthProviderInfo {
id: string;
@@ -29,7 +27,6 @@ export interface AuthProviderRuntime {
export function getLoginProviderOptions(runtime: AuthProviderRuntime, authType?: AuthType): AuthProviderOption[] {
const providers = runtime.getProviders();
const oauthProviderIds = new Set(providers.filter((provider) => provider.auth.oauth !== undefined).map((provider) => provider.id));
const options: AuthProviderOption[] = [];
for (const provider of providers) {
@@ -44,7 +41,6 @@ export function getLoginProviderOptions(runtime: AuthProviderRuntime, authType?:
for (const provider of providers) {
if (provider.auth.apiKey === undefined) continue;
if (!isApiKeyLoginProvider(provider.id, oauthProviderIds)) continue;
options.push({
id: provider.id,
name: provider.name,
@@ -70,13 +66,6 @@ export async function getLogoutProviderOptions(runtime: AuthProviderRuntime): Pr
return filterAndSort(options);
}
export function isApiKeyLoginProvider(providerId: string, oauthProviderIds: ReadonlySet<string>): boolean {
if (OAUTH_ONLY_PROVIDERS.has(providerId)) return false;
if (providerId === "anthropic") return true;
if (oauthProviderIds.has(providerId)) return false;
return true;
}
function filterAndSort(options: AuthProviderOption[], authType?: AuthType): AuthProviderOption[] {
const filtered = authType === undefined ? options : options.filter((option) => option.authType === authType);
return filtered.sort((a, b) => a.name.localeCompare(b.name) || a.authType.localeCompare(b.authType) || a.id.localeCompare(b.id));