different-ai/openwork · error
t("providers.oauth_method_required")
Error message
t("providers.oauth_method_required") What it means
createProviderAuthStore throws this when starting a provider OAuth flow with a methodIndex that is not a non-negative integer. The store indexes into the provider's list of OAuth sign-in methods, so a fractional, negative, or non-numeric index cannot select a method and the flow is aborted before any network call. It is a fail-fast input validation guard.
Source
Thrown at apps/app/src/react-app/domains/connections/provider-auth/store.ts:1559
async function completeProviderAuthOAuth(
providerId: string,
methodIndex: number,
code?: string,
) {
setStateField("providerAuthError", null);
const c = options.client();
if (!c) {
throw new Error(t("providers.not_connected"));
}
const resolved = providerId?.trim();
if (!resolved) {
throw new Error(t("providers.provider_id_required"));
}
assertProviderAllowedByDesktopPolicy(resolved);
if (!Number.isInteger(methodIndex) || methodIndex < 0) {
throw new Error(t("providers.oauth_method_required"));
}
const waitForProviderConnection = async (timeoutMs = 15000, pollMs = 2000) => {
const startedAt = Date.now();
while (Date.now() - startedAt < timeoutMs) {
try {
const updated = await refreshProviders({ dispose: true });
const connected = new Set(updated?.connected ?? []);
if (connected.has(resolved)) {
return true;
}
} catch {
// ignore and retry
}
await new Promise((resolve) => setTimeout(resolve, pollMs));
}
return false;
};View on GitHub (pinned to 2b7df46e8a)
Solutions
- Pass the zero-based index of a valid OAuth method for the resolved provider.
- Validate the index before calling: Number.isInteger(i) && i >= 0.
- If the index came from saved state/URL, re-resolve it against the provider's current method list instead of reusing it.
- For flows with a single method, pass 0 explicitly.
Example fix
// before
store.startProviderOAuth(providerId, -1);
// after
const methodIndex = provider.oauthMethods.findIndex((m) => m.id === wantedMethodId);
if (methodIndex < 0) throw new Error("Unknown OAuth method");
store.startProviderOAuth(providerId, methodIndex); Defensive patterns
Strategy: validation
Validate before calling
const idx = Number(methodIndex);
if (!Number.isInteger(idx) || idx < 0) throw new Error(`Invalid OAuth method index: ${methodIndex}`); Type guard
function isValidMethodIndex(v: unknown): v is number {
return typeof v === "number" && Number.isInteger(v) && v >= 0;
} Try / catch
try {
store.startProviderOAuth(providerId, methodIndex);
} catch (e) {
if (String((e as Error).message).includes("oauth_method_required")) {
showInvalidMethodMessage();
}
} Prevention
- Always pass a zero-based integer index resolved from the provider's method list
- Never use -1 as a sentinel; use null/undefined and skip the call instead
- Coerce URL/state-derived values with Number() and validate before use
- Re-resolve indexes after provider method lists change
When it happens
Trigger: Calling the OAuth start action with methodIndex = -1, 1.5, NaN, undefined, or a string like "2" from UI code or tests; passing a stale index after the provider's method list changed.
Common situations: Off-by-one or default -1 sentinel values; deriving the index from an untrusted URL param or query string; forgetting to update the index after a provider adds/removes an OAuth method.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- `${t("providers.no_oauth_prefix")} ${resolved}. ${t("provide
- `${t("providers.not_oauth_flow_prefix")} ${resolved}.`
- t("providers.api_key_required")
- OpenWork-managed OAuth requires a remote MCP URL.
- app.error_session_name_required
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/b70b53758b9fcb27.
Report an issue: GitHub.