Primary finding
Inconsistent config compatibility: tryResolveOAuthProfile rejects token credentials when config.mode is "oauth", but resolveApiKeyForProfile allows it
mediumbughigh
- src/agents/auth-profiles/oauth.ts:106-112
- src/agents/auth-profiles/oauth.ts:151-156
- src/agents/auth-profiles/oauth.ts:219-224
resolveApiKeyForProfile explicitly treats config.mode "oauth" as compatible with stored token-based credentials, but tryResolveOAuthProfile strictly enforces mode equality. In fallback flows, resolveApiKeyForProfile delegates to tryResolveOAuthProfile, which will then reject otherwise compatible token credentials, causing unnecessary failures.
Recommendation
Align tryResolveOAuthProfile with the compatibility rule used in resolveApiKeyForProfile; allow config.mode "oauth" to accept stored token credentials. Alternatively, bypass tryResolveOAuthProfile in the fallback when the stored credential is a token and handle it similarly to resolveApiKeyForProfile.